==============================================================
Script: Draggable Elements / Drag In Drop Images Functions: A versatile
script that enables any image(s) and
text on a page to be dragable.
Comments: The script is in two parts.
Browsers: NS4-7 & IE4 and later
==============================================================
STEP 1.
Inserting the JavaScript <script> In Your Page
Put the following <script> </script> in the head
section of your page.
There are no setups or changes required.
<style>
<!--
.drag{position:relative;cursor:hand}
-->
</style>
<script language="JavaScript1.2">
<!--
/*
Drag and Drop Script-
© Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/
var dragapproved=false
var z,x,y
function move(){
if (event.button==1&&dragapproved){
z.style.pixelLeft=temp1+event.clientX-x
z.style.pixelTop=temp2+event.clientY-y
return false
}
}
function drags(){
if (!document.all)
return
if (event.srcElement.className=="drag"){
dragapproved=true
z=event.srcElement
temp1=z.style.pixelLeft
temp2=z.style.pixelTop
x=event.clientX
y=event.clientY
document.onmousemove=move
}
}
document.onmousedown=drags
document.onmouseup=new Function("dragapproved=false")
//-->
</script>
==============================================================
STEP 2.
Inserting The Code In Your Page
To apply drag-drop capabilities by simply adding this
line class="drag" into the <img> tags you want to drag, like
this:
<img src="your_image.gif" class="drag"><br>
<img src="your_image.gif" class="drag"><br>
This goes for any element. To make whatever you want
draggable add the CLASS tag from above to any givin tag.
|