jQuery hoverIntent Plugin show / hide div on parent hover, but keep showing when hovered

前端 未结 1 1945
时光取名叫无心
时光取名叫无心 2021-01-26 04:25

I have a button that when hovered over (mouseover) displays a div right below it. When hovered away (mouseout), the div disappears.

This all works well and nicely, bu

相关标签:
1条回答
  • 2021-01-26 05:08

    Stick another div #wrapperDiv around both the button and the #displayDiv and attach hoverIntent to #wrapperDiv rather than the button:

    $('#wrapperDiv').hoverIntent(function () {
       $("#displayDiv").stop().slideDown('slow');
    },
    function () {
       // I don't want the div to hide if user hovers over it
       $("#displayDiv").stop().slideUp('slow');
    });
    

    HTML:

    <div id="wrapperDiv">
       <div id="hoverMeToShowHideDiv"> // some stuff </div>
       <div id="displayDiv"> 
          // some other stuff that I want to 
          // keep showing if users hover over it 
       </div>
    </div>
    
    0 讨论(0)
提交回复
热议问题