Je débute dans javascript, et j'essai de créer un effet de drag n drop, mais pour le moment j'essui un échec critique. J'ai notamment un sacré problème sur la portée des variables, et je ne sais comment le régler. Bien que je les déclare hors de toute fonction, le fait de les modifier dans une fonction ne me permet pas d'y accéder à travers une autre fonction
Voici le code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> #dean { border:1px solid red; background-color:blue; width:75px; height:75px; position:absolute; } </style> <script language='javascript'> var mouseX; var mouseY; var innerMX; var innerMY; var xObj; var yObj; var wObj; var hObj; var e; var Obj; var dragin; function move(Obj){ e = window.event; mouseX = e.x; mouseY = e.y; xObj = Obj.offsetLeft; yObj = Obj.offsetTop; wObj = Obj.offsetWidth; hObj = Obj.offsetHeight; dragin = true; Obj = document.getElementById(Obj); //Obj.style.left=mouseX; Obj.style.top=mouseY; } function clear(){ if( dragin == true ){ dragin = false; Obj = ''; } } function moving(){ if( dragin == true ){ //Obj.style.left = mouseX; Obj.style.top = mouseY; alert(Obj+' '+mouseX+' '+mouseY); } } </script> </head> <body onmouseup='clear()' onmousemove='moving()'> <input type='text' id='infos' onmousedown='move("infos")'/> <div> <div id='dean' onmousedown='move("dean")'></div> </div> </body> </html>
Quelqu'un pourrait-il m'aider?
En vous remerciant,
Smoke


