Combining Raphael and jQuery to achieve browser compatibility

前端 未结 5 1853
梦谈多话
梦谈多话 2021-01-02 06:52

Having discovered that IE does not handle javascript onmouseout, I\'m determined to use jQuery instead so the cross-browser compatibility would be taken care of

5条回答
  •  心在旅途
    2021-01-02 07:47

    In my case, the actual problem was with calling the .toFront every freakin millisecond, because .hover(fooFunction, outFunction) calls fooFunction with every mouse cursor shift. Actually, the name quite suggests that it's a hover call, not a mouseenter :)

    So, the trick is to make sure your fooFunction, or the contents of it, is only executed once (onmouseenter). Even in IE this works perfectly for me, without accessing any DOM nodes or trying to access other stuff which I don't want to touch:

    var MouseEventHelper = {
        hover: function (el, funcIn, funcOut) {
            var entered = false;
    
            el.hover(
                function (e) {
                    if (entered) {
                        return;
                    }
    
                    funcIn(e);
                    entered = true;
                },
                function (e) {
                    funcOut(e);
                    entered = false;
                }
            );
        }
    }
    

    Then replace your hover calls like this:

    var el = paper.rect(...);
    MouseEventHelper.hover(
        el, 
        function (e) { 
            // do whatever you want!
            el.toFront();
        }
        function (e) { }
    );
    

提交回复
热议问题