Computing.Net > Forums > Programming > dragging the image in javascript

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

dragging the image in javascript

Reply to Message Icon

Name: priti
Date: October 15, 2003 at 23:07:25 Pacific
OS: win xp
CPU/Ram: p4
Comment:

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.



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: dragging the image in javascript

Display an image in DOS www.computing.net/answers/programming/display-an-image-in-dos/12671.html

Background image in HTML www.computing.net/answers/programming/background-image-in-html/8726.html

Problem in JavaScript, Help Plz! www.computing.net/answers/programming/problem-in-javascript-help-plz/7606.html