jxrd Posted May 27, 2009 Share Posted May 27, 2009 Hello, I've been working on a drag and drop thing, and it works fine in IE, but not in FF, which is odd. It's normally the other way round. For some reason, Firefox just moves it once...it's weird. Test out my script and you'll see what I mean: <script type="text/javascript"> function drag(element, event) { //init drag document.body.onmousemove = function() { drag_Move(element, event); } document.body.onmouseup = function() { document.body.onmousemove = null; } } function drag_Move(element, event) { with(element) { style.top = (event.pageY) ? event.pageY+'px' : event.clientY + document.body.scrollTop+'px'; style.left = (event.pageX) ? event.pageX +'px' : event.clientX + document.body.scrollTop+'px'; } } </script> <body> <a id="drag" style="position: absolute;" onmousedown="drag(this, event);">yo</a> I've been working at this for ages, and I can't get it to work. Any help would be greatly appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/159926-drag-and-drop-almost-there/ Share on other sites More sharing options...
iPixel Posted May 27, 2009 Share Posted May 27, 2009 Perhaps this can help. It seems many ppl are having this issue. http://www.google.com/search?hl=en&q=onmousemove+firefox&aq=0&oq=onmousemove+fire&aqi=g2 Quote Link to comment https://forums.phpfreaks.com/topic/159926-drag-and-drop-almost-there/#findComment-843507 Share on other sites More sharing options...
jxrd Posted May 27, 2009 Author Share Posted May 27, 2009 !!!! I think I figured out what it is. I'm calling the function with an onmousedown event. I think maybe the mousemove event not being passed is causing the problem. For example, if you add this to the code: <body style="height: 1000px;" onclick="drag(document.getElementById('drag'), event);"> it works fine, but obviously it's constantly moving. So yeah, you wouldn't happen to know how to create a mousemove event would you? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/159926-drag-and-drop-almost-there/#findComment-843517 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.