1 <html> 2 <body> 3 4 <style> 5 <!-- 6 .dragme{position:relative;} 7 --> 8 </style> 9 <script language="JavaScript1.2"> 10 <!-- 11 12 var ie=document.all; 13 var nn6=document.getElementById&&!document.all; 14 15 var isdrag=false; 16 var x,y; 17 var dobj; 18 19 function movemouse(e) 20 { 21 if (isdrag) 22 { 23 if (e && e.clientX) 24 { 25 dobj.style.left = tx + e.clientX - x; 26 dobj.style.top = ty + e.clientY - y 27 } 28 else 29 { 30 dobj.style.left = tx + event.clientX - x; 31 dobj.style.top = ty + event.clientY - y; 32 } 33 return false; 34 } 35 } 36 37 function selectmouse(e) 38 { 39 var fobj; 40 var topelement; 41 if (e && e.target) 42 { 43 fobj = e.target; 44 topelement = "HTML"; 45 } 46 else 47 { 48 fobj = event.srcElement; 49 topelement = "BODY"; 50 } 51 52 while (fobj.tagName != topelement && fobj.className != "dragme") 53 { 54 if (fobj.parentNode) 55 { 56 fobj = fobj.parentNode; 57 } 58 else 59 { 60 fobj = fobj.parentElement; 61 } 62 } 63 64 if (fobj.className=="dragme") 65 { 66 isdrag = true; 67 dobj = fobj; 68 tx = parseInt(dobj.style.left+0); 69 ty = parseInt(dobj.style.top+0); 70 if (e && e.clientX) 71 { 72 x = e.clientX; 73 y = e.clientY; 74 } 75 else 76 { 77 x = event.clientX; 78 y = event.clientY; 79 } 80 81 document.onmousemove=movemouse; 82 return false; 83 } 84 } 85 86 document.onmousedown=selectmouse; 87 document.onmouseup=new Function("isdrag=false"); 88 89 //--> 90 </script> 91 92 93 94 <img src="icon.gif" class="dragme" id="test1"><br> 95 <img src="icon.gif" class="dragme" id="test2"><br> 96 <b>"Hi there</b> 97 <div style="position: absolute; left: 210px; top: 80px; height: 400px; width: 100px; padding: 10em;"> 98 <img src="icon.gif" class="dragme" id="test3"><br> 99 <img src="icon.gif" class="dragme" id="test4"><br> 100 </div> 101 </body> 102 </html>