Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Modify Drag script

Reply
Thread Tools

Modify Drag script

 
 
DanWeaver
Guest
Posts: n/a
 
      02-12-2007
I am trying to modify the below script which allows elements of
class="drag" to be dragged around the screen by a user- am new to
javascript and learning this along with vbscript (which I understand
better), ajax and HTML. I need to get (either as a hidden text box or
a variable to be used in other functions (including vbscript
functions) the coordinates of a dragged object after the drag
operation ie to know exactly where each draggable element is at all
times.
Any help massively appreciated. Dan.

<style type="text/css">
.drag{
position:relative;
cursor:hand;
z-index: 100;
}
</style>
<script type="text/javascript">
/***********************************************
* Drag and Drop Script: Dynamic Drive (http://
www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s
more.
***********************************************/
var dragobject={
z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj :
null, dragapproved : 0,
initialize:function(){
document.onmousedown=this.drag
document.onmouseup=function(){this.dragapproved=0}
},
drag:function(e){
var evtobj=window.event? window.event : e
this.targetobj=window.event? event.srcElement : e.target
if (this.targetobj.className=="drag"){
this.dragapproved=1
if (isNaN(parseInt(this.targetobj.style.left)))
{this.targetobj.style.left=0}
if (isNaN(parseInt(this.targetobj.style.top)))
{this.targetobj.style.top=0}
this.offsetx=parseInt(this.targetobj.style.left)
this.offsety=parseInt(this.targetobj.style.top)
this.x=evtobj.clientX
this.y=evtobj.clientY

if (evtobj.preventDefault)
evtobj.preventDefault()
document.onmousemove=dragobject.moveit
}
},
moveit:function(e){
var evtobj=window.event? window.event : e
if (this.dragapproved==1){
this.targetobj.style.left=this.offsetx+evtobj.clie ntX-this.x
+"px"
this.targetobj.style.top=this.offsety+evtobj.clien tY-this.y
+"px"
return false
}
}
}

dragobject.initialize()
</script>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
script/console : modify an attribute Guillaume Loader Ruby 2 02-19-2009 05:23 PM
modify output of script Kt Br Ruby 2 05-13-2008 09:49 PM
py script modify it's Modified Time? est Python 3 04-12-2007 07:05 AM
modify a long-running python script while it is running? Benjamin Rutt Python 2 12-20-2005 01:42 PM
A compatible drag-n'-drop script VK Javascript 1 06-02-2005 01:02 AM



Advertisments