Tricky delay on mouseover

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

    Use the setTimeout to check if a flag you set/unset (I'm using a class) is still valid.

    $("#cart-summary").mouseenter(function () {
        $("#cart-summary").addClass("hasFocus");
        setTimeout(function(){ 
            if ($("#cart-summary").hasClass("hasFocus")) {
                $('.flycart').slideDown('fast');
            }
          }, 500 );
          });
    
    $("#cart-summary").mouseleave(function () {
        $("#cart-summary").removeClass("hasFocus");
    });
    
    
    $(".flycart").mouseenter(function () {
        $("#cart-summary").removeClass("lostFocus");    
    });
    
    $(".flycart").mouseleave(function () {
        $("#cart-summary").addClass("lostFocus");
        setTimeout(function(){ 
            if ($("#cart-summary").hasClass("hasFocus")) { 
                $('.flycart').slideUp('fast');
                }).find('a.close').click(function(){
                $(this).parents('.flycart').hide();
            }
        }, 500)
    });
    

提交回复
热议问题