Tricky delay on mouseover

前端 未结 5 2239
借酒劲吻你
借酒劲吻你 2021-02-14 14:10

This is what I have currently:

$(\"#cart-summary\").mouseenter(function () {
    $(\'.flycart\').delay(500).slideDown(\'fast\');
});
$(\".flycart\").mouseleave(f         


        
5条回答
  •  失恋的感觉
    2021-02-14 14:59

    You could do:

    var timeout,
        $flycart = $(".flycart"),
        $summary = $("#cart-summary"),
        delay = 500;
    
    $summary.mouseenter(function () {
        if (timeout) window.clearTimeout(timeout);
        timeout = window.setTimeout(function(){
            if ( $flycart.is(":visible") ) {
                $flycart.slideDown('fast');
            }
        }, delay);
    });
    $flycart.mouseleave(function () {
        if (timeout) window.clearTimeout(timeout);
        timeout = window.setTimeout(function(){
            if ( $flycart.is(":visible") ) {
                $flycart.slideUp('fast');
            }
        }, delay);
    })...
    

提交回复
热议问题