raphael icon indicating copy to clipboard operation
raphael copied to clipboard

toFront removes events in internet explorer 6

Open johnwards opened this issue 13 years ago • 16 comments

If I call toFront on a element it removes the mouseover/hover event in internet explorer.

What I am doing is stacking rectangles on a graph. On mouse over I am animating them to be slightly bigger and have an outline. On mouse out they animate back to the correct scale. This works perfectly if I remove the toFront call. I need the toFront call so we can see the bigger rectangle rather than it being hidden behind the one I have plotted above it.

johnwards avatar Sep 09 '10 15:09 johnwards

Replicated in ie7 and ie8 also.

johnwards avatar Sep 10 '10 07:09 johnwards

Appears to remove moueout, mouseenter, mouseleave and click events as well. Likely others. Seen in IE6, IE7 and IE8

albertsun avatar Oct 18 '10 22:10 albertsun

I have a SO post open on this issue.

http://stackoverflow.com/questions/3686132/move-active-element-loses-mouseout-event-in-internet-explorer

Basically toFront uses:

this.parentNode.appendChild(this);

To move the item further down the dom. If your mouse is over the element that is being moved down the dom, internet explorer doesn't register your mouse being moved out.

This is a bug with internet explorer, so toFront might need rethought somehow?

My solution was to replicate the mouse in/out by monitoring the "box" of the element being moved. If the pointer moved outside of the box then fire a mouse out function.

Very hacky as it involves monitoring mouse positions, but its only attached on mouseover (which does work) and the even is removed by the new mouse monitoring code.

johnwards avatar Oct 19 '10 10:10 johnwards

Okay so I now know what is happening as explained in this answer on the question which I posted to stack overflow.

http://stackoverflow.com/questions/3686132/move-active-element-loses-mouseout-event-in-internet-explorer/4006353#4006353

To quote:

The problem is that IE handles mouseover differently, because it behaves like mouseenter and mousemove combined on an element. In other browsers it's just mouseenter.

So even after your mouse has entered the target element and you've changed it's look and reappended it to it's parent mouseover will still fire for every movement of the mouse, the element gets reappended again, which prevents other event handlers from being called.

How I have handled this is to put a boolean value on my created element.

var el = paper.path();
el.mouseovered = false;
el.mouseover(function(){
  if(this.mouseovered==false)
  {
    this.mouseovered=true;
    this.toFront();
  }
});

el.mouseout(function(){
   this.toBack();
   this.mousedover = false;
});

johnwards avatar Oct 26 '10 07:10 johnwards

This is great, thanks.

albertsun avatar Oct 26 '10 14:10 albertsun

cheers john - great fix for a bug that's been frustrating me all morning

wheresrhys avatar Apr 06 '11 11:04 wheresrhys

Be careful with this. You can get it into a state where the mouseout isn't fired correctly. If the thing you are building effects the performance of the browser overall you can move the mouse quicker than events and things can get in a funny state.

johnwards avatar Apr 06 '11 11:04 johnwards

Maybe another possible fix (when jQuery is present) would be to have something like the following if(!evData.raphIgnore) { this.toFront(); $(this.node).trigger("mouseenter", {raphIgnore: true}); }

... but then you'd need to use jQuery, not Raphael, listeners in order to be able to access the data passed in

wheresrhys avatar Apr 06 '11 11:04 wheresrhys

Replicated this issue in iOS as well. http://jsfiddle.net/vitorbarbosa/FAGkY/

After the first drag event is performed (mouseup/ontouchend) the element loses the events associated to the drag.

vitorhsb avatar Oct 13 '11 11:10 vitorhsb

Here's a straightforward example. http://jsfiddle.net/K2bSY/2/

In the first circle, which has no boolean toggle on the mouseover event, IE incorrectly loops the mouseover event infinite times and fails to fire the mouseout event.

In the second circle, which is identical except for a boolean toggle disabling the mouseover event until mouseout has occurred, IE behaves like normal browsers. Not only does the mouseover event occur only once, but the mouseout event occurs as normal.

The third circle simply shows that there are no issues when toFront() is not called.

alanomaly avatar Mar 12 '12 10:03 alanomaly

Is this happening in the latest version?

tomasAlabes avatar Feb 06 '13 02:02 tomasAlabes

I am still seeing this with Raphael 2.1.0 in IE9 and Opera 12.14.

nikolaik avatar Mar 22 '13 13:03 nikolaik

This is still an issue even in IE10.

zpconn avatar Dec 05 '13 22:12 zpconn

And in IE11 as well.

Would be great if it could be fixed or worked around in an official Raphael version!

JorisDebonnet avatar Feb 16 '14 03:02 JorisDebonnet

Hi guys, This bug is still valid with Raphael 2.1.2 and IE11. Do you plan to fix this in the near future?

piotrkulpinski avatar Dec 16 '14 10:12 piotrkulpinski

More then 5 years old bug still present in IE :(

jerone avatar Jan 26 '16 10:01 jerone