HTML |
<html> <head><title></title></head> <script> var cof=false; function downm(){ dyn=window.event.srcElement; down(); } function down(){ xmin=parseInt(window.event.offsetX); ymin=parseInt(window.event.offsetY); cof=true; } function drag(){ if(cof==true){ xmos=parseInt(window.event.x); ymos=parseInt(window.event.y); dyn.style.left=xmos-xmin+document.body.scrollLeft; dyn.style.top=ymos-ymin+document.body.scrollTop; } } </script> <body onmousemove="drag()"> <form onmousedown="downm()" onmouseup="cof=false"> <div style="position:absolute;width:100;height:100;background-color:00ff33;top:10;left:10"></div> <div style="position:absolute;width:100;height:100;background-color:003453;top:10;left:100"></div> <div style="position:absolute;width:100;height:100;background-color:000000;top:10;left:210"></div> <div style="position:absolute;width:100;height:100;background-color:ffcc55;top:10;left:310"></div> <div style="position:absolute;width:100;height:100;background-color:ccff33;top:10;left:410"></div> <div style="position:absolute;width:100;height:100;background-color:1d2344;top:10;left:510"></div> </form> </body> </html> |
HTML |
<html> <head><title></title></head> <script> var cof=false; function downm(){ dyn=window.event.srcElement; down(); } function down(){ xmin=parseInt(window.event.offsetX); ymin=parseInt(window.event.offsetY); cof=true; } function drag(){ if(cof==true){ xmos=parseInt(window.event.x); ymos=parseInt(window.event.y); dyn.style.left=xmos-xmin+document.body.scrollLeft; dyn.style.top=ymos-ymin+document.body.scrollTop; } } function coords(){ xmos=parseInt(window.event.x); ymos=parseInt(window.event.y); xmin=parseInt(window.event.offsetX); ymin=parseInt(window.event.offsetY); px=xmos-xmin+document.body.scrollLeft; py=ymos-ymin+document.body.scrollTop; alert(px+' x '+py) } </script> <body onmousemove="drag()"> <div onmousedown="downm()" onmouseup="cof=false;coords()"> <div style="position:absolute;width:100;height:100;background-color:00ff33;top:10;left:10"></div> <div style="position:absolute;width:100;height:100;background-color:003453;top:10;left:110"></div> <div style="position:absolute;width:100;height:100;background-color:000000;top:10;left:210"></div> <div style="position:absolute;width:100;height:100;background-color:ffcc55;top:10;left:310"></div> <div style="position:absolute;width:100;height:100;background-color:ccff33;top:10;left:410"></div> <div style="position:absolute;width:100;height:100;background-color:1d2344;top:10;left:510"></div> </div> </body> </html> |