Drag and drop the image!

Y

yihan

Hi,
I made a program to drag and drop the image using mouseevent, it only works
on IE well, not on Netscape. Does anyone has the example suitable for
Netscape? Please help. Thank you very much.

yihan
 
F

Fabian

yihan hu kiteb:
Hi,
I made a program to drag and drop the image using mouseevent, it only
works on IE well, not on Netscape. Does anyone has the example
suitable for Netscape? Please help. Thank you very much.

Can you show us the code? It might only require minor tweaking to fit.
And its something I want to do for one of my own projects too. You
wouldn't want to save me loads of time would you :)
 
L

Lasse Reichstein Nielsen

Fabian said:
yihan hu kiteb:
Can you show us the code? It might only require minor tweaking to fit.
And its something I want to do for one of my own projects too. You
wouldn't want to save me loads of time would you :)

Very simple example (dragging, no effect on dropping):
---
<script type="text/javascript">
function dragImg(img,evt,how) {
how = how || "relative";
img.style.position = how;
var root = document.documentElement || document.body;
var x = img.xPos || (how == "relative" ? 0 : img.offsetLeft);
var y = img.yPos || (how == "relative" ? 0 : img.offsetTop);
var mx = evt.pageX || evt.clientX + root.scrollLeft;
var my = evt.pageY || evt.clientY + root.scrollTop;
document.onmousemove = function (evt){
evt = evt || window.event;
var newmx = evt.pageX || evt.clientX + root.scrollLeft;
var newmy = evt.pageY || evt.clientY + root.scrollTop;
x += newmx - mx;
y += newmy - my;
mx = newmx;
my = newmy;
img.style.left = x+"px";
img.style.top = y+"px";
img.style.outline="2px solid gray";
img.style.zIndex = "1";
return false;
}
document.onmouseup = function () {
document.onmousemove = document.onmouseup = null;
img.xPos = x;
img.yPos = y;
img.style.outline = img.style.zIndex = "";
return false;
}
return false;
}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top