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 :

Animation a partir d'une image


Sujet :

jQuery

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Février 2008
    Messages
    183
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : France, Sarthe (Pays de la Loire)

    Informations forums :
    Inscription : Février 2008
    Messages : 183
    Points : 96
    Points
    96
    Par défaut Animation a partir d'une image
    bonjour,

    Je souhaite faire une animation a partir d'une image qui compose 25 images (dans une seule)
    Voici l'images : Lien de l'image

    et je voudrais faire que toutes les images forme une animation sur 1s 750 ms

    J'ai fait un truc en javascript qui vas bien trop vite, j'ai l'impression de passer de la première image a la dernière d'un coup. et moi je voudrais que 1s 750 ms a 2 seconde max se passe entre la première et la dernière image d'une même image.

    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
     
    <div id="magiName" style="width: 64px; height: 64px; display: inline-block; background: url('Images/sorts_animate/3_25.png') no-repeat; position:absolute; background-position: left top; z-index:1000;" ></div>
     
    $(function()
    {			
    	$("#magiName").on('click', function()
    	{	
    		$(this).css("background-position", "-64px top");
    		$(this).css("background-position", "-128px top");
    		$(this).css("background-position", "-192px top");
    		$(this).css("background-position", "-256px top");
    		$(this).css("background-position", "left -64px");
    		$(this).css("background-position", "-64px -64px");
    		$(this).css("background-position", "-128px -64px");
    		$(this).css("background-position", "-192px -64px");
    		$(this).css("background-position", "-256px -64px");
    		$(this).css("background-position", "left -128px");
    		$(this).css("background-position", "-64px -128px");
    		$(this).css("background-position", "-128px -128px");
    		$(this).css("background-position", "-192px -128px");
    		$(this).css("background-position", "-256px -128px");
    		$(this).css("background-position", "left -192px");
    		$(this).css("background-position", "-64px -192px");
    		$(this).css("background-position", "-128px -192px");
    		$(this).css("background-position", "-192px -192px");
    		$(this).css("background-position", "-256px -192px");
    		$(this).css("background-position", "left -256px");
    		$(this).css("background-position", "-64px -256px");
    		$(this).css("background-position", "-128px -256px");
    		$(this).css("background-position", "-192px -256px");
    		$(this).css("background-position", "-256px -256px");					
    	});
    });
    J'ai aussi essayer de faire comme ça, mais la ça marche carrément pas ? pourquoi ?

    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
    $(function()
    {			
    	$("#magiName").on('click', function()
    	{		
    		$(this).animate({"background-position": "left top"}, { duration : 500 } );
    		$(this).animate({"background-position": "-64px top"}, { duration : 500 } );
    		$(this).animate({"background-position": "-128px top"}, { duration : 500 } );
    		$(this).animate({"background-position": "-192px top"}, { duration : 500 } );
    		$(this).animate({"background-position": "-256px top"}, { duration : 500 } );
    		$(this).animate({"background-position": "left -64px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-64px -64px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-128px -64px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-192px -64px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-256px -64px"}, { duration : 500 } );
    		$(this).animate({"background-position": "left -128px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-64px -128px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-128px -128px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-192px -128px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-256px -128px"}, { duration : 500 } );
    		$(this).animate({"background-position": "left -192px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-64px -192px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-128px -192px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-192px -192px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-256px -192px"}, { duration : 500 } );
    		$(this).animate({"background-position": "left -256px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-64px -256px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-128px -256px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-192px -256px"}, { duration : 500 } );
    		$(this).animate({"background-position": "-256px -256px"}, { duration : 500 } );					
    	});
    });
    Pouvez vous m'aider.

    Merci d'avance

  2. #2
    Expert éminent
    Avatar de sekaijin
    Homme Profil pro
    Urbaniste
    Inscrit en
    Juillet 2004
    Messages
    4 205
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 60
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Urbaniste
    Secteur : Santé

    Informations forums :
    Inscription : Juillet 2004
    Messages : 4 205
    Points : 9 127
    Points
    9 127
    Par défaut
    merci de poste les questio JQuery dans le forum JQuery

    il te faut faire appel à la fonction javascript setTimeout ou setInterval qui te permet d''exécuter une fonction au bout d'un certain temps.

    http://www.w3schools.com/js/js_timing.asp

    je ne sais pas si JQuery propose quelque chose.
    A+JYT

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Février 2008
    Messages
    183
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : France, Sarthe (Pays de la Loire)

    Informations forums :
    Inscription : Février 2008
    Messages : 183
    Points : 96
    Points
    96
    Par défaut
    Merci.

    Je réaliser ça avec setTimeout comme ceci et ça fonctionne nickel.

    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
     
    var curS = 0;		
    		$("#magiName").on('click', function() {					
    			timer();
    		});
    		function timer()
    		{
                var bgP = new Array("left top", "-64px top","-128px top","-192px top","-256px top",
    								"left -64px", "-64px -64px", "-128px -64px", "-192px -64px", "-256px -64px",
    								"left -128px", "-64px -128px", "-128px -128px", "-192px -128px", "-256px -128px",
    								"left -192px", "-64px -192px", "-128px -192px", "-192px -192px", "-256px -192px",
    								"left -256px", "-64px -256px", "-128px -256px", "-192px -256px", "-256px -256px");			
                if (curS <= (bgP.length - 1))
    			{
    				document.getElementById("magiName").style.backgroundPosition = bgP[curS];
                }       
    			curS++;
    			if(curS != (bgP.length - 1))
    				setTimeout(timer,24);
            }

  4. #4
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17 088
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17 088
    Points : 44 663
    Points
    44 663
    Par défaut
    Bonjour,
    il eut mieux valu faire une image horizontale ou verticale pour n'avoir à jouer que sur un paramètre, top ou left.

    Tant qu'a utiliser jQuery, il existe .each() qui pourrait être utilisé ici.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Lien internet a partir d'une image
    Par Furlaz dans le forum C++Builder
    Réponses: 28
    Dernier message: 15/06/2006, 13h57
  2. Animation a partir d'une mosaique d'image
    Par winston44 dans le forum C++Builder
    Réponses: 3
    Dernier message: 16/01/2006, 20h54
  3. [C#] custom control à partir d'une image / alpha blending
    Par Cyberwan dans le forum Windows Forms
    Réponses: 5
    Dernier message: 13/11/2005, 21h59
  4. appel de fonction à partir d'une image activer/desactiver
    Par philippe123 dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 23/08/2005, 16h26
  5. Réponses: 3
    Dernier message: 27/01/2005, 10h53

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