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

JavaScript Discussion :

setInterval mouvement image


Sujet :

JavaScript

  1. #1
    Membre à l'essai
    Inscrit en
    Mai 2009
    Messages
    24
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2009
    Messages : 24
    Points : 22
    Points
    22
    Par défaut setInterval mouvement image
    Bonjour,

    je voudrais faire bouger une image pour cela je pensais utiliser setInterval mais je n'y arrive pas

    donc voila mon code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    function defilementImage(id, positionInitialX, positionInitialY, positionFinalX, positionFinalY, pasX, pasY)
    {
    	var image = document.getElementById(id); 
    	image.style.display = '';
    	if(positionInitialX < positionFinalX && positionInitialY < positionFinalY){
    		image.style.left = positionInitialX+'px';
    		image.style.top = positionInitialY+'px';
    		positionInitialX += pasX;
    		positionInitialY += pasY;
    		//alert(image.style.left);
    		time =setInterval(function(){defilementImage(id, positionInitialX, positionInitialY, positionFinalX, positionFinalY, pasX, pasY);},4);
    	}
    }
    si quelqu'un a une idee

    Merci

  2. #2
    Membre à l'essai
    Inscrit en
    Mai 2009
    Messages
    24
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2009
    Messages : 24
    Points : 22
    Points
    22
    Par défaut
    en changeant le if par un while et en mettant une alert(); on note que l'image se deplace bien donc c est que ca va trop vite

  3. #3
    Membre à l'essai
    Inscrit en
    Mai 2009
    Messages
    24
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2009
    Messages : 24
    Points : 22
    Points
    22
    Par défaut
    peronne n'a d'idee ???

  4. #4
    Membre à l'essai
    Inscrit en
    Mai 2009
    Messages
    24
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2009
    Messages : 24
    Points : 22
    Points
    22
    Par défaut
    a ce que j ai compris c est que :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    setInterval(function{mafct(parametre);},40);
    rappelle ma fonction toutes les 40 milli secondes

    et la fonction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    setTimeout(function{mafct(parametre);},40);
    appelle ma fonction au bout de 40 millisecondes

    mais est ce que sa bloque le srcipt derriere comme un wait

  5. #5
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 640
    Points : 66 665
    Points
    66 665
    Billets dans le blog
    1
    Par défaut
    un petit exemple :
    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
    <html>
     
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Nouvelle page 2</title>
    <script language="Javascript">
    var timer;
    var position= new Array(2);
    var MyWay;
     
    function movearound(thisway)
    { 
    position[0] = parseInt(document.getElementById('MyDiv').style.top);
    position[1] = parseInt(document.getElementById('MyDiv').style.left); 
     
    switch(thisway)
    {
    case "up":
       position[0] -= 2;
       break;
     
    case "do":
       position[0] += +2;
       break;
     
    case "le":
       position[1] -= 2;
       break;
    case "ri":
       position[1] += +2;
       break;
    }
     
     
    document.getElementById('MyDiv').style.top = Number(position[0]); 
    document.getElementById('MyDiv').style.left = Number(position[1]);
    } 
     
    </script> 
    <style >
    input {font-family: 'symbol';}
    </style>
    </head>
     
     
    <body>
    <div id="MyDiv" style="width: 39; height: 20; top:0; left:0; background-color: blue; position: absolute; z-index:-1;" ></div> 
     
     
      <table border="0" style="cellpadding:0; cellspacing:0; " width="90">
        <tr>
          <td width="33%"></td>
          <td width="33%"><input type="button" name="up" width=this.height value="Ý" onClick="a=this.name; clearInterval(timer); timer=setInterval('movearound(a)',10);" ; / / / /></td>
          <td width="34%"></td>
        </tr>
        <tr>
          <td width="33%"><input type="button" name="le" width="100" value="Ü" onClick="a=this.name; clearInterval(timer); timer=setInterval('movearound(a)',10);" /></td>
          <td width="33%"><input type="button" width="100" value="&#128;" onClick="clearInterval(timer);" /></td>
          <td width="34%"><input type="button" name="ri" width="100" value="Þ" onClick="a=this.name;clearInterval(timer); timer=setInterval('movearound(a)',10);" /></td>
        </tr>
        <tr>
          <td width="33%"></td>
          <td width="33%"><input type="button" name="do" width="100" value="ß" onClick="a=this.name;clearInterval(timer); timer=setInterval('movearound(a)',10);" /></td>
          <td width="34%"></td>
        </tr>
      </table>
     
    </html>

Discussions similaires

  1. Effet mouvement image
    Par Invité dans le forum Interfaces Graphiques en Java
    Réponses: 1
    Dernier message: 21/03/2012, 00h24
  2. Mouvement image picturebox à la souris
    Par Lnmex dans le forum Windows Forms
    Réponses: 2
    Dernier message: 14/03/2009, 12h30
  3. Interpolation d'images (mouvement)
    Par Sammy44 dans le forum Traitement d'images
    Réponses: 1
    Dernier message: 18/11/2007, 14h53
  4. Réponses: 7
    Dernier message: 01/05/2007, 21h55
  5. suivre un objet en mouvement sur image
    Par jlf dans le forum Traitement du signal
    Réponses: 24
    Dernier message: 09/05/2005, 13h46

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