JQuery Special Event HoverIntent与“ Mouseleave”功能无法正常使用



我很难让jQuery特殊事件hoverintent使用mouseleave功能。(我还尝试用mouseout代替mouseleave

我需要使用相同的功能,以便仅当用户的鼠标在灵敏度阈值下方放慢速度时才会发射mouseleave事件。

我已经包含了下面的脚本,还将工作示例上传到http://click2fit.com/test_files/accordion_hoverintent.html

$(function () {     
    $(".accordion_close_leave").accordion({
                event: "click hoverintent",
                collapsible: true,
                active: false,     
                autoHeight: false,
             }).mouseleave(function() {
    $(this).accordion({ active: false}); 
    });  
var cfg = ($.hoverintent = {
    sensitivity: 100,
    interval: 500
});
$.event.special.hoverintent = {
    setup: function() {
        $( this ).bind( "mouseover", jQuery.event.special.hoverintent.handler );
    },
    teardown: function() {
        $( this ).unbind( "mouseover", jQuery.event.special.hoverintent.handler );
    },
    handler: function( event ) {
        var that = this,
            args = arguments,
            target = $( event.target ),
            cX, cY, pX, pY;
        function track( event ) {
            cX = event.pageX;
            cY = event.pageY;
        };
        pX = event.pageX;
        pY = event.pageY;
        function clear() {
            target
                .unbind( "mousemove", track )
                .unbind( "mouseout", arguments.callee );
            clearTimeout( timeout );
        }
        function handler() {
            if ( ( Math.abs( pX - cX ) + Math.abs( pY - cY ) ) < cfg.sensitivity ) {
                clear();
                event.type = "hoverintent";
                event.originalEvent = {};
                jQuery.event.handle.apply( that, args );
            } else {
                pX = cX;
                pY = cY;
                timeout = setTimeout( handler, cfg.interval );
            }
        }
        var timeout = setTimeout( handler, cfg.interval );
        target.mousemove( track ).mouseout( clear );
        return true;
    }
};

事实证明,jQuery的HoverIntent特殊事件代码在这里无法使用,因为它是专门为包含在手风琴的事件选项的设计(定义为手风琴标题对订单的事件做出反应的事件激活相关的面板)。

好消息是,Brian Cherne的HoverIntent插件确实:D我包括下面的脚本,并且可以在此处提供一个工作小提琴:http://jsfiddle.net/chayacooper/gzv5v/26/

重要的是要记住将Mouseleave绑定到手风琴本身,以便在用户将鼠标从整个手风琴中取出之前,它不会被触发。如果用户在进入该标题时立即单击标头,则有一个小问题,但是我愿意接受这一点,以便能够在手风琴中使用某些元素。

$(document).ready(function() {
$("#Trigger2").accordion({
    active: false,
    collapsible: true
}).hoverIntent({
    over: function() {},
    out: function() {
        $('.ui-accordion-header-active', this).trigger('click').blur();
    },
    timeout: 1000
})
.children('h3').hoverIntent({
    over: function() {
        $(this).not('.ui-accordion-header-active').trigger('click');
    },
    out: function() {},
    timeout: 1000
});
});

最新更新