Metachecker.net
|
TrafficChecker.net
|
RankChecker.net
Learn Java Script Today
|
Over 5000 Free Fonts
|
Tutorials
|
Javascript Forum
|
Other Javascript Resources
|
Cheat Sheet
JavaScript Basics
Inserting Javascript
Complete Tutorial
Advance DHTML Tutorial
Script archive
Advanced Tutorials
Alert Scripts
Animation
Audio
Background Effects
Banner Ads
Browser Window
Buttons
Button Forms
Calculcators
Calendars
Clocks & Dates
Cookies
Cursor Effects
DHMTL Games
DHTML Miscellaneous
Equivalents
Forms
Games
IE4+ Scripts
IE5+ Scripts
Image Effects
Image Miscellaneous
Links & Buttons
Math Related
Messages Miscellaneous
Miscellaneous
Mouse Tricks
Navigation
Page Details
Password Protection
Pulldown Menus
Random Stuff
Scrolling
Status Bar
Text Animation
User Detail
User Info
Window Control
Dragable Elements Script
A versatile script that enables any image(s) and text on a page to be dragable.
Drag The Images.
Insert into <HEAD>
<style> <!-- .drag{position:relative;cursor:hand} --> </style> <script language="JavaScript1.2"> <!-- 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>
Insert into <BODY>
Other Options
Once the script is installed, enabling any image on the page to be dragable is a snap. Lets take the following html document as an example: <html> <head> <!--drag engine code installed here--> </head> <body> <img src="test.gif"><br> <img src="test2.gif"><br> <b>"Hi there</b> </body> </html> To apply drag-drop capabilities to the first two images above, simply add the line class="drag" into the <img> tags, like this: <html> <head> <!--drag engine code installed here--> </head> <body> <img src="test.gif" class="drag"><br> <img src="test2.gif" class="drag"><br> <h1><b>"Hi there</b></h1> </body> </html> The two images will now move when the mouse drags them. What about text elements, you say? Well, the engine handles them just as well: <html> <body> <img src="test.gif"><br> <img src="test2.gif"><br> <h1><b class="drag">Hi there</b></h1> </body> </html> Hi there Notice that the class="drag" declaration is added to the innermost element, the <b> element, and not the <h1> element.