Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag & Drop

Status
Not open for further replies.

ozenet

Programmer
Oct 25, 2003
4
0
0
AU
Hi

Can anyone tell me why the following code works fine with the text but not with the image.

I only care about ie5+.

Any help would be appreciated.

<html>
<head>
<script type=&quot;text/javascript&quot;>
function dragObj(obj,nest)
{
nest=(!nest) ? '':'document.'+nest+'.'
this.css=eval('document.all.'+obj+'.style')
this.evnt=eval(obj);
this.getLeft=b_getLeft;
this.getTop=b_getTop;
this.moveIt=b_moveIt;
this.name=obj
return this
}
function b_moveIt(x,y)
{
this.x=x; this.y=y;
this.css.left=this.x
this.css.top=this.y
}
function b_getLeft()
{
x=this.css.pixelLeft
return x
}
function b_getTop()
{
y=this.css.pixelTop
return y
}
function dragInit()
{
document.onmousedown=mdown
document.onmouseup=mup
document.onmousemove=mmove;
}
function mmover(num)
{
if(loaded) oDrag[num].isOver=true
}
function mmout(num)
{
if(loaded) oDrag[num].isOver=false
}
function mup()
{
for(var i=0; i<oDrag.length;i++)
{
if(oDrag.isOver) {oDrag.drag=false}
}
}
function mdown(num)
{
x=event.x
y=event.y
for(var i=0; i<oDrag.length;i++)
{
if(oDrag.isOver)
{
oDrag.drag=true
oDrag.clickedX=x-oDrag.getLeft()
oDrag.clickedY=y-oDrag.getTop()
}
}
}
function mmove()
{
x=event.x
y=event.y
for(var i=0; i<oDrag.length;i++)
{
if(oDrag.drag)
oDrag.moveIt(x-oDrag.clickedX,y-oDrag.clickedY)
}
}
</script>
</head>

<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0
onload=&quot;init();&quot;
>

<div id=&quot;image1&quot; style=&quot;position:absolute; left:0px; top:0px; width:80px; height:100px; z-index:5; visibility:visible&quot;
onmouseover=&quot;mmover(0)&quot;;
onmouseout=&quot;mmout(0)&quot;;
>
<IMG height=100 alt=&quot;&quot; src=&quot;albert_th.gif&quot; width=80 border=0 name=image1img>
</DIV>

<div id=&quot;textbox1&quot; style=&quot;position:absolute; left:200px; top:0px; width:100px; height:50px; z-index:5; visibility:visible&quot;
style=&quot;cursor:hand&quot;;
onmouseover=&quot;mmover(1)&quot;;
onmouseout=&quot;mmout(1)&quot;;
>
Text Works
</DIV>
</body>

<script language=&quot;javascript&quot;><!--
function init()
{
dragInit();
oDrag=new Array();
oDrag[0]=new dragObj('image1');
oDrag[1]=new dragObj('textbox1');
loaded=true;
}
--></script>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top