IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

jQuery Discussion :

Languette glissante verticale


Sujet :

jQuery

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 3
    Par défaut Languette glissante verticale
    Bonjour,

    Je souhaite faire des languettes animées pour un menu

    donc pour une languette horizontale j'ai ce code qui marche nickel avec animate:

    pour le javascript :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $('#mondiv').hover(function(){ $(this).animate({'background-position':'0px'}); },function(){ $(this).animate({'background-position':'-30px'}); });
    pour ma div :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <div id="mondiv" style="background-image:url(languette.png); background-position:-30px; height: 22px; width: 120px; background-repeat: no-repeat;">&nbsp;</div>
    Comment faire pour avoir le même résultat en vertical ?

    Merci d'avance

  2. #2
    Rédacteur

    Avatar de danielhagnoul
    Homme Profil pro
    Étudiant perpétuel
    Inscrit en
    Février 2009
    Messages
    6 389
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 75
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant perpétuel
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2009
    Messages : 6 389
    Billets dans le blog
    125
    Par défaut
    Bonsoir

    Pour animer un "background-position" (deux paramètres), j'utilise depuis longtemps le code d'Alexander Farkas. Il existe peut-être une nouvelle version ou un autre moyen, je n'ai pas cherché. J'ai mis trois exemples d'animation verticale.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    <!doctype html>
    <html lang="fr">
    <head>
    	<meta charset="utf-8">
    	<meta name="Author" content="Daniel Hagnoul">
    	<title>Forum jQuery</title>
    	<style>
    		/* Base */
    		div,p,h1,h2,h3,h4,h5,h6,ul,ol,dl,form,table,img {margin:0px; padding:0px; }
    		body {background-color:#dcdcdc; color:#000000; font-family:sans-serif; font-size:medium; font-style:normal; font-weight:normal; line-height:normal; letter-spacing:normal; }
    		h1,h2,h3,h4,h5 {font-family:serif; padding:6px; }
    		p, div, td {word-wrap:break-word; }
    		pre, code {white-space:pre-wrap; word-wrap:break-word; }
    		img, input, textarea, select {max-width:100%; }
            img {border:none; }
    		h1 {font-size:2em; text-shadow: 4px 4px 4px #bbbbbb; text-align:center; }
    		p {padding:6px; }
            ul,ol,dl {list-style:none; padding-left:6px; padding-top:6px; }
            li {padding-bottom:6px; }
    		.conteneur {width:95%; min-width:800px; min-height:400px; margin:12px auto; background-color:#FFFFFF; color:#000000; border:1px solid #666666; }
     
    		/* bottomPanel */
    		#mondiv {
    			background-image:url('http://danielhagnoul.developpez.com/images/imageTest.png');
    			background-position:-30px 0px;
    			background-repeat: no-repeat;
    			height: 22px;
    			width: 120px;
    			border:1px solid red;
    		}
    		#mondivVert1 {
    			background-image:url('http://danielhagnoul.developpez.com/images/imageTest.png');
    			background-position:0px 70%;
    			background-repeat: no-repeat;
    			height: 120px;
    			width: 22px;
    			border:1px solid red;
    		}
    		#mondivVert2 {
    			background-image:url('http://danielhagnoul.developpez.com/images/imageTest.png');
    			background-position:0px 130%;
    			background-repeat: no-repeat;
    			height: 120px;
    			width: 22px;
    			border:1px solid red;
    		}
    		#mondivVert3 {
    			background-image:url('http://danielhagnoul.developpez.com/images/imageTest.png');
    			background-position:0px -30%;
    			background-repeat: no-repeat;
    			height: 120px;
    			width: 22px;
    			border:1px solid red;
    		}
    	</style>
    </head>
    <body>	
    	<h1>Forum jQuery</h1>
    	<section class="conteneur">
    		<div id="mondiv"></div>
    		<br/>
    		<div id="mondivVert1"></div>
    		<br/>
    		<div id="mondivVert2"></div>
    		<br/>
    		<div id="mondivVert3"></div>
    	</section>
    	<footer itemscope itemtype="http://data-vocabulary.org/Person">
    		<time datetime="2011-06-06T22:45:00.000+02:00" pubdate>2011-06-06</time> <span itemprop="name">Daniel Hagnoul</span> <a href="http://www.developpez.net/forums/u285162/danielhagnoul/" itemprop="url">@danielhagnoul</a>
    	</footer>
    	<script charset="utf-8" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
    	<script>
    		/**
    		 * @author Alexander Farkas
    		 * v. 1.02
    		 */
    		(function($) {
    			$.extend($.fx.step,{
    				backgroundPosition: function(fx) {
    					if (fx.state === 0 && typeof fx.end == 'string') {
    						var start = $.curCSS(fx.elem,'backgroundPosition');
    						start = toArray(start);
    						fx.start = [start[0],start[2]];
    						var end = toArray(fx.end);
    						fx.end = [end[0],end[2]];
    						fx.unit = [end[1],end[3]];
    					}
    					var nowPosX = [];
    					nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
    					nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
    					fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
     
    				   function toArray(strg){
    					   strg = strg.replace(/left|top/g,'0px');
    					   strg = strg.replace(/right|bottom/g,'100%');
    					   strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
    					   var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
    					   return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
    				   }
    				}
    			});
    		})(jQuery);
     
    		$(function(){
    			$('#mondiv').hover(
    				function(){
    					$(this).animate({"background-position": "(0px 0px)"}, 500);
    				},
    				function(){
    					$(this).animate({"background-position": "(-30px top)"}, 500);
    				}
    			);
     
    			$('#mondivVert1').hover(
    				function(){
    					$(this).animate({"background-position": "(0px 100%)"}, 500);
    				},
    				function(){
    					$(this).animate({"background-position": "(0px 70%)"}, 500);
    				}
    			);
     
    			$('#mondivVert2').hover(
    				function(){
    					$(this).animate({"background-position": "(0px 100%)"}, 500);
    				},
    				function(){
    					$(this).animate({"background-position": "(0px 130%)"}, 500);
    				}
    			);
     
    			$('#mondivVert3').hover(
    				function(){
    					$(this).animate({"background-position": "(0px 100%)"}, 500);
    				},
    				function(){
    					$(this).animate({"background-position": "(0px -30%)"}, 500);
    				}
    			);
    		});
    	</script>
    </body>  
    </html>

    Blog

    Sans l'analyse et la conception, la programmation est l'art d'ajouter des bogues à un fichier texte vide.
    (Louis Srygley : Without requirements or design, programming is the art of adding bugs to an empty text file.)

Discussions similaires

  1. [CR9] Centrer verticalement le texte
    Par CDRIK dans le forum SAP Crystal Reports
    Réponses: 3
    Dernier message: 22/05/2009, 19h33
  2. [CR7] Peut on afficher un champ verticalement
    Par yoyothebest dans le forum SAP Crystal Reports
    Réponses: 3
    Dernier message: 31/08/2004, 09h26
  3. La taille verticale de mes panels
    Par szdavid dans le forum Débuter
    Réponses: 7
    Dernier message: 21/04/2004, 11h10
  4. Synchronisation verticale
    Par hs_dino dans le forum OpenGL
    Réponses: 2
    Dernier message: 28/09/2003, 09h35
  5. VGA : synchro verticale (et horizontale ?)
    Par Blustuff dans le forum Assembleur
    Réponses: 19
    Dernier message: 21/06/2003, 08h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo