PDA

View Full Version : Drag & Drop



oClient
Apr 28th, 2007, 06:32 PM
Sorry about my last post.
There is some problem when I tried to make a drag gable image. Before I write: return = false
It sometimes stops dragging. Why should it use the return statement?
In what condition do we have to use this way? Is it only for events?


<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 2</title>
<script language="javascript">
function $(id){
return document.getElementById(id);
}
var bToggle = 0;
var obj;
var ix;
var iy;
function Moving(obj,iX,iY){
document.onmousemove=function(e){
if(bToggle){
e = e || event;
obj.style.left = e.clientX - iX;
obj.style.top = e.clientY - iY;
}
return false;
}
}
window.onload=function(){
$("img1").onmousedown = function(e){
bToggle = 1;
e = e || event;
ix = e.clientX - this.offsetLeft;
iy = e.clientY - this.offsetTop;
Moving(this,ix,iy);
return false;
}
$("img1").onmouseup=function(){
bToggle = 0;
}
}
</script>
</head>

<body>
<img id="img1" src="disc.jpg" style="position:absolute;top:90;" width="150" height="150"/>
</body>

</html>