Jquery - Delay mouseout event

女生的网名这么多〃 提交于 2019-12-10 10:04:31

问题


Is there a way to make jquery wait a certain about amount of time before mouseout event is fired?

It is firing too early at the moment and I'd prefer to wait 500ms before it evaluates the mouse out. An example of the code I'm using below.

$('.under-construction',this).bind({
    mousemove: function(e) {
        setToolTipPosition(this,e);
        css({'cursor' : 'crosshair' });
    },
    mouseover: function() {
        $c('show!');
        showUnderConstruction();
    },
    mouseout: function() {
        $c('hide!');
        hideUnderConstruction();
    },
    click: function() {
        return false;
    }
});

Is there a jquery way to do this or will I have to do it myself?


回答1:


Split the logic inside the mouseout into another function. in the mouseout even call this function with a setTimeout("myMouseOut", 500). And you can combine the mouseover event with a clearTimeout() to reset the timer if the user moves into a new element.




回答2:


You could always wrap your logic in a setTimeout() function.

mouseout: function() {
  setTimeout(function(){
    $c('hide!');
    hideUnderConstruction();
  }, 500);
}



回答3:


You might check out the hoverIntent plugin lets you define some vars that help with mouseenter/out interactions



来源:https://stackoverflow.com/questions/2267402/jquery-delay-mouseout-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!