Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I have written javascript which creates rectangle shape. (I didn't use .gif but i created rectangle using <div>tag (Actually i got this idea from SN. Thanks SN)).
I want to drag that image which i have created. In style i have used position: relative; which allows me to change the position of the image. But now when I try to drag the rectangle it doesn't move. I tried using position: absolute; but still it's not working.
Below is the code which I'm using:function mouseDown(){
obj = event.srcElement.parentElement.style;
obj.zIndex=99;
x=event.offsetX;
y=event.offsetY;
}
function mouseMove(){
if(obj){
obj.pixelLeft = event.clientX-x + document.body.scrollLeft;
obj.pixelTop = event.clientY-y + document.body.scrollTop;
return false;
}
}
function mouseUp(){
obj.zIndex=99;
obj = null;
}
document.onMouseDown = mouseDown;
document.onMouseMove = mouseMove;
document.onMouseUp = mouseUp;
</SCRIPT>
<STYLE>
div.rect {
position:relative;
height: 100px;
width: 250px;
background-color: red;
top:0;
left:0;
}
</STYLE>
In the body part i've following:
<STYLE>
div.rect {
position:absolute;
height: 100px;
width: 250px;
background-color: red;
top:70;
left:33;
}
</STYLE>
</HEAD>
<body">
<form name="form1">
<table width="60%" align="left">
<tr>
<td width="40%" align="left" valign="left">
<DIV class="rect" ID="myDIV"></DIV>Any help will be greatly appreciated.
Thanks.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |