...

View Full Version : Drag-event in IE



Deltran
10-19-2005, 04:59 PM
I have a div that I can drag on mousedown. In Firefox the code works as expected. In IE, however, it does not work anymore.

I noticed that if you put the mousemove event listener on the div that I'm dragging that it will get lost if you move the mouse wildly across the screen. So I decided to put the even on the window.

Now you can move the mouse as fast as you want in FireFox. In IE, however, it moves a little then stops - not reacting at all.

Is there some kind of quirk here?

Thanks a bunch!

_Aerospace_Eng_
10-19-2005, 05:01 PM
Umm hard for us to tell you without any code. We aren't psychic.

Deltran
10-19-2005, 05:10 PM
Sorry - I didn't see this as a code-specific problem. But if I was right I probably wouldn't have to ask for help, LOL. So, upon request:


var dragMe = document.getElmentById('dragger');


function startDrag(e, textValue){
var evt = new xEvent(e);

var ourText = document.createTextNode(textValue);
dragMe.appendChild(ourText);
dragMe.style.display='inline';

if(evt.attachEvent){
dragMe.style.top = (evt.clientY -10) + 'px';
dragMe.style.left = (evt.clientX -10)+ 'px';
} else {

dragMe.style.top = (evt.pageY -10) + 'px';
dragMe.style.left = (evt.pageX -10)+ 'px';
}
xAddEventListener(window, 'mousemove', whileDrag, true);
xAddEventListener(dragMe, 'mouseup', endDrag, false);
}

function whileDrag(e){
//alert('entering');
var evt = new xEvent(e);
//reposition the div to where we currently are
if(evt.attachEvent){
dragMe.style.top = (evt.clientY -10) + 'px';
dragMe.style.left = (evt.clientX -10)+ 'px';
} else {
dragMe.style.top = (evt.pageY -10) + 'px';
dragMe.style.left = (evt.pageX -10)+ 'px';
}
}


EDIT: I observed that the function whileDrag isn't getting called at all. IE isn't giving me a yellow-triangle-of-death, and if you put an alert statement at the end of startDrag() it fires.

Deltran
10-19-2005, 05:19 PM
Hate to double post, however I found a solution.

IE doesn't like window on listeners - it prefers document.body :confused: :mad:

Whatever it wants.
Thanks for looking - I hope this helps someone out someday at least :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum