Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery延迟事件_Jquery_Delay - Fatal编程技术网

Jquery延迟事件

Jquery延迟事件,jquery,delay,Jquery,Delay,我需要推迟mouseleave上的removeClass。我可以简单地添加一条this.delay线吗?您可以使用 你可以用 只有当鼠标位于元素外部时,removeClass“active”才会执行操作 通过这种方式。removeClass“active”仅在鼠标位于元素外部时才会执行操作。一点建议:不是mouseenter,而是mouseleave use.hover…,…一点建议:不是mouseenter,而是mouseleave use.hover…,…这将不是超时内的元素。这将不是超时内

我需要推迟mouseleave上的removeClass。我可以简单地添加一条this.delay线吗?

您可以使用

你可以用

只有当鼠标位于元素外部时,removeClass“active”才会执行操作


通过这种方式。removeClass“active”仅在鼠标位于元素外部时才会执行操作。

一点建议:不是mouseenter,而是mouseleave use.hover…,…一点建议:不是mouseenter,而是mouseleave use.hover…,…这将不是超时内的元素。这将不是超时内的元素。
$('#cart > .heading a').bind('mouseenter', function() {
    $('#cart').addClass('active');


    $.ajax({
        url: 'index.php?route=checkout/cart/update',
        dataType: 'json',
        success: function(json) {
            if (json['output']) {
                $('#cart .content').html(json['output']);
            }
        }
    });         

    $('#cart').bind('mouseleave', function() {
        $(this).removeClass('active');
    });
});
$('#cart').bind('mouseleave', function() {
    var $that = $(this);
    setTimeout(function(){$that.removeClass('active');}, 500); //500 millisec delay
});
$('#cart > .heading a').hover(function() {
    // clear the previously defined timeout if any
    clearTimeout($(this).data('timeout'));
    $(this).addClass('active');
    // do other stuff here
}, function() {
    // set timeout and save it in element's state
    // so it could be removed later on if needed
    var e = $(this).data('timeout', setTimeout(function() {
        e.removeClass('active');
    }, 3 * 1000)); // 3 sec.
});