IE UI doesn't update in mousemove event

R

Robert

I have implemented some custom scrollbars and implemented drag&drop
functionality to update the position of the scrollbar while dragging.
The problem I am having is that in IE the scrollbar position doesn't
update very good while dragging fast. It seems that the mousemove
events happen so fast in IE that it forgets to "repaint" the updated
position on the scrollbar. Note that in Firefox it works perfectly
fine.

To solve this I thought about intercepting the mousemove calls and
only call the listener with the mousemove event argument only once
per interval (for example 100ms). I implemented this using
window.setTimeout
and stumbled upon another problem.

The event variable (containing properties such as screenX and screenY)
is "saved" before the setTimeout delay and passed to the listener in
the callback function. However it seems that the event object is
reused (in Firefox and IE), so the properties do not contain the same
values as when the timeout began. You can probably imagine the problems
that this causes.

To solve this I needed to copy/clone the event object. Now I ended
up with some weird event copy function.

function cloneEvent(evt)
{
// For Firefox:
//var result = document.createEvent("MouseEvent");

// For IE:
var result = document.createEventObject("MouseEvent");

/* For Firefox:
result.initMouseEvent(
"mousemove",
evt.bubbles, // PRBool canBubbleArg
evt.cancelable, // PRBool cancelableArg
evt.view, // nsIDOMAbstractView viewArg
evt.detail, // PRInt32 detailArg
evt.screenX, // PRInt32 screenXArg
evt.screenY, // PRInt32 screenYArg
evt.clientX, // PRInt32 clientXArg
evt.clientY, // PRInt32 clientYArg
evt.ctrlKey, // PRBool ctrlKeyArg
evt.altKey, // PRBool altKeyArg
evt.shiftKey, // PRBool shiftKeyArg
evt.metaKey, // PRBool metkeyArg
evt.button, // PRUint16 buttonArg
evt.relatedTarget // nsIDOMEventTarget relatedTargetArg
);
*/

// For IE:
for (var i in evt)
{
try
{
result = evt;
}
catch(e) {}
}

return result;
}

It all works now, but I wanted to know if there is a cleaner/easier
way to solve my original problem. Some questions are:
1) Is there a way to reduce the rate that IE triggers mousemove events?
2) Can I force IE to update the UI before a new event is called?
3) Can I copy the event in IE with a function such as Firefox?

Kind regards,
Robert
 

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

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top