This is a sample program to create a drag and drop using javascript.
|
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 69 70 71 72 73 74 75 76 |
<html> <head> <title>Javascript Drag and Drop Example.</title> <style type="text/css"> .vidFrame { position: absolute; display: none; background-color: #ffdead; border: 1px solid #800000; width: 435px; height: 362px; cursor: move; } .moveable { position: absolute; cursor: move; } </style> <script language="JavaScript" type="text/javascript"> var selObj = null; function playVid(vidId) { if (vidPaneID.style.display=='block') { vidPaneID.style.display='none'; vidPaneID.innerHTML=''; } } function moveHandler(e){ if (e == null) { e = window.event } if (e.button<=1&&dragOK){ selObj.style.left=e.clientX-dragXoffset+'px'; selObj.style.top=e.clientY-dragYoffset+'px'; return false; } } function cleanup(e) { document.onmousemove=null; document.onmouseup=null; selObj.style.cursor=orgCursor; dragOK=false; } function dragHandler(e){ var htype='-moz-grabbing'; if (e == null) { e = window.event; htype='move';} var target = e.target != null ? e.target : e.srcElement; selObj=target; orgCursor=target.style.cursor; if (target.className=="vidFrame"||target.className=="moveable") { target.style.cursor=htype; dragOK=true; dragXoffset=e.clientX-parseInt(selObj.style.left); dragYoffset=e.clientY-parseInt(selObj.style.top); document.onmousemove=moveHandler; document.onmouseup=cleanup; return false; } } document.onmousedown=dragHandler; </script> </head> <body> <img src='Tree.jpg' class='moveable' id='movePic'> <div id='vidPane' class='vidFrame'></div> <script language="JavaScript" type="text/javascript"> var orgCursor=null; var dragOK=false; var dragXoffset=0; var dragYoffset=0; vidPaneID = document.getElementById('vidPane'); vidPaneID.style.top='75px'; vidPaneID.style.left='75px'; document.getElementById('movePic').style.left='500px'; document.getElementById('movePic').style.top='100px'; </script> </body> </html> |






