Tricky delay on mouseover

前端 未结 5 2268
借酒劲吻你
借酒劲吻你 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:52

    offer a solution

    var mouseenterTimerCart;
    var mouseleaveTimerCart;
    
    $(document).on({
        mouseenter: function () {
            if (mouseleaveTimerCart) clearTimeout(mouseleaveTimerCart);
            mouseenterTimerCart = setTimeout(function() {
                $("#head-cart .cart_items").show()
            }, 500);
        },
        mouseleave: function () {
            if (mouseenterTimerCart) clearTimeout(mouseenterTimerCart);
            mouseleaveTimerCart = setTimeout(function() {
                $("#head-cart .cart_items").hide()
            }, 500);
        }
    }, "#head-cart .full, #head-cart .cart_items");
    

    will work if the basket is updated dynamically

    $("#head-cart").html(...crat-html-block...)
    

提交回复
热议问题