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 :

Déplacement d'un div


Sujet :

JavaScript

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 5
    Points : 3
    Points
    3
    Par défaut Déplacement d'un div
    Bonjours a tous

    Voila je souhaiterai déplacer un div d'un point A a une point B

    j'ai fait une function pour cela et je souhaiterai avoir une tempo entre chaque exécution de ma boucle for pour qu'on puisse voir les déplacement.

    voici 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
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
    function deplacer(){
     
    	var posx1 = 37;
    	var posy1 = 19;
    	var posx2 = 48;
    	var posy2 = 43;
    	var posx3 = 12;
     
    	for( var i=0; i<70; i++){
     
    		var timer = setInterval('deplacer',14);
    		var posx1 = posx1-0.1 ;
    		var posy1 = posy1-0.1 ;
    		var posx2 = posx2+0.1 ;
    		var posy2 = posy2+0.1 ;
    		var posx3 = posx3-0.1 ;
    		document.getElementById("parti4").style.top=posx1+"%";
    		document.getElementById("parti4").style.left=posy1+"%";
    		document.getElementById("parti2").style.top=posx2+"%";
    		document.getElementById("parti2").style.left=posy2+"%";
    		document.getElementById("parti1").style.top=posx3+"%";
     
    		if(posx1 == 30){
    			clearInterval(timer);
    		}
    	}
    }

  2. #2
    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
    tiens j'ai retrouvé un vieux code de mes débuts ^^
    ce n'est pas sans une certaine émotion que je l'exhume

    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. Déplacement d'une DIV avec la souris
    Par PtitGénie dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 24/02/2009, 11h35
  2. Déplacement d'un div sous IE6
    Par chichoune dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 01/10/2008, 11h43
  3. Déplacement d'une DIV
    Par rafiq25 dans le forum Général Dotnet
    Réponses: 3
    Dernier message: 08/02/2008, 16h09
  4. Déplacement dans une div scrollable
    Par kankrelune dans le forum Général JavaScript
    Réponses: 10
    Dernier message: 30/05/2006, 21h52
  5. Déplacement d'un div
    Par krfa1 dans le forum Général JavaScript
    Réponses: 15
    Dernier message: 21/10/2005, 11h02

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