Add delay to mouseleave in jquery

后端 未结 4 1867
隐瞒了意图╮
隐瞒了意图╮ 2021-01-13 04:07

I\'m using this code in my site and I was wondering how I could add a delay to the mouseleave function

$target.mouseenter(function(e){
                var $t         


        
4条回答
  •  滥情空心
    2021-01-13 04:56

    The problem with just a timer would be if you mouse left and then re-entered it would still hide after that timer completed. Something like the following might work better because we can cancel the timer whenever the mouse enters the target.

    var myTimer=false;
    $target.hover(function(){
        //mouse enter
        clearTimeout(myTimer);
    },
    function(){
        //mouse leave
        var $tooltip=$("#"+this._tipid);
        myTimer = setTimeout(function(){
            ddimgtooltip.hidebox($, $tooltip);
        },500)
    });
    

提交回复
热议问题