Hovering over a set of elements in Raphaeljs

后端 未结 4 1429
囚心锁ツ
囚心锁ツ 2021-01-03 06:26

I have a set that only contains a rectangle.

var hoverTrigger = this.paper.set();
var outline = this.paper.rect();
outline.attr({
...
hoverTrigger.push(outli         


        
4条回答
  •  醉话见心
    2021-01-03 07:15

    I hit on this problem before. I found 2 solutions.

    Create a rectangle over other elements with opacity set to 0

    var paper = new Raphael( 0, 0, 100, 100 );
    var rect = paper.rect( 0, 0, 100, 100 ).attr({ opacity: 0 });
    rect.hover( func_in, func_out );
    

    This only works for elements that have 1 overall action like click.

    The other option is to cancel the hover function when hovering over a set of elements

    var funcOutTimer;
    
    set.hover( function( ) {
        if( funcOutTimer ) { // Hovered into this element in less than 100 milliseconds => cancel
            window.clearTimeout( funcOutTimer);
        } else {
        // do stuff
        }
    },
    function( ) {
        funcOutTimer = setTimeout( function( ) {
            // do stuff
        }, 100 ); // wait for 100 milliseconds before executing hover out function
    });
    

    Basically the hover in function is only executed when first entering a set of elements for the first time and the hover out function will only execute once when finally the element you have hovered into is not part of that set.

提交回复
热议问题