How to solve this hover out issue

后端 未结 2 1355
旧时难觅i
旧时难觅i 2020-12-22 05:10

I am trying to apply a hover in and hover out effect on a button and a div will popup above the hovered button. The popup div will disappear if user hover out of the button.

相关标签:
2条回答
  • 2020-12-22 05:19

    This is how you solve issues with hover on different elements etc :

    var timer;
    
    $('.helpImg').on({
        mouseenter: function() {
            clearTimeout(timer);
            $(this).css({'cursor': 'pointer'});
            $('#tool').show(150);
        },
        mouseleave: function() {
            timer = setTimeout(function() {
                $(this).css({'cursor': 'auto'});
                $('#tool').hide(50);
            }, 300);
        }
    });
    
    $("#tool").on({
        mouseenter: function() {
            clearTimeout(timer);
        },
        mouseleave: function() {
            $(this).hide(50);
        }
    });
    

    FIDDLE

    0 讨论(0)
  • 2020-12-22 05:32

    Try:

    $('.helpImg').css({'cursor': 'pointer'}).hover(function(){
        $('#tool').show(150);
    }, function (){
        $('#tool').not(':visible').hide(50);
    });
    
    $('#tool').mouseout(function(){ this.style.display = 'none'; })     
    
    0 讨论(0)
提交回复
热议问题