将hoverIntent与.on或delegate一起使用

Using hoverIntent with .on or delegate

本文关键字:一起 delegate hoverIntent on      更新时间:2023-09-26

如何将hoverIntent与一起使用

    $mainNav.on('mouseenter', '.hEvent', function () {
       //Do stuff
    });

使用"选择器"选项进行事件委派。

$mainNav.hoverIntent({
        over: function() {
        },
        out: function(){
        },
        selector: '.hEvent'
});

来源:hoverIntent文档

实际上,直接使用delegate()使用'hover'或'hoverIntent'之类的东西有点棘手,因为hover不是一个ACTUAL事件,但它由两个不同的事件组成,即mouseentermouseleaf。因此,悬停实际上是一个伪事件。此信息可在此处找到:http://api.jquery.com/hover/

现在,关于处理伪事件:这应该是可行的,代码也是不言自明的。假设您需要将hoverIntent绑定到#child

    $('#parent').delegate(
       '#child',
       'hoverIntent',
       function (evt) {
           if (evt.type === 'mouseenter')
               $(this).find('.tooltip').fadeIn();
           else
               $(this).find('.tooltip').hide();
   });

希望这能有所帮助D

.hEvent被用作选择器,对吗?据我所知,hoverIntent插件有一个名为over的选项,它接受一个函数,该函数与onMouseOver同义(如jQuery MouseEnter事件)。

难道你不能使用:

$(".hEvent").hoverIntent(over: function() {
    //Do stuff
});