Jump to content

dragging element inside div


siri

Recommended Posts

Hi,Here is the code I tried for dragging the element inside the div tag. But the code doesn't seems to work in mozilla and netscape.It works fine in IE.Can anyone kindly let me know where exactly things are going wrong ?Code:**************************************************************** <script type ="text/javascript"> var ie =false; var mousex; var tempx; var temp; function init() { if(document.addEventListener) { document.getElementById("i1").addEventListener("mousedown",display,true); } else { ie=true; } } function display(e) { mousex = e.pageX; } function move(obj) { temp = obj; tempx = parseInt(obj.style.left); if(ie) { mousex = event.clientX; } else { document.captureEvents(Event.MOUSEMOVE); } document.onmousemove = drag; document.onmouseup = drop; } function drag(e) { var pos=0; if(ie) { pos = tempx + (event.clientX - mousex); } else { pos = tempx + (e.pageX - mousex); } var limit = parseInt(document.getElementById("m1").style.width) - parseInt(temp.style.width); document.getElementById("t1").value = tempx; document.getElementById("t2").value = mousex; if(pos >= 0 && pos <= limit) { temp.style.left = pos; document.getElementById("d1").style.left = pos + 24 ; document.getElementById("d1").innerText = pos; } return false; } function drop() { document.onmousemove = null; document.onmouseup = null; } </script></head><body onload="init()"><div id="m1" style=" position:relative; width:300px;height:125px; cursor:pointer"> <img src ="slider001.gif" id="i1" alt="slide" style="position:absolute;left:10px;top:10px;width:58px" onmousedown = "move(this)" /> <div id="d1" style="position:absolute;left:30px;top:10px; color:White; font-weight:bold"></div> </div>*******************************************************************

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...