jQuery Hide/Show with Slide on Hover… better way to do this?

前端 未结 2 1121
日久生厌
日久生厌 2021-01-03 04:49

Basically having some trouble with using Hover to hide or show an item.

The idea is simple, on hover show a div. When no longer hovering, hide it. Problem is if

相关标签:
2条回答
  • 2021-01-03 05:13

    I tried your script and it did as you described. I tried removing the children.is(":hidden") from your script, but the problem still occurred.

    When I rewrote it the script the div never stays visible. So, it appears that the problem is with using jQuery's children instead of find to get to the object:

    Still has problems:

     jQuery (
       function(){
         jQuery(".slideDiv").hide();
         jQuery(".mainDiv").hover (
           function() {
             $(this).children(".slideDiv").show("slide", { direction: "left" }, 100);
           },function(){
             $(this).children(".slideDiv").hide("slide", { direction: "left" }, 100);
           }
         );
       }
     );
    

    Works as intended:

     $(document).ready(function(){
       $('.slideDiv').hide();
       $('.mainDiv').hover(
         function(){
           $(this).find('.slideDiv').show('slide', { direction: 'left' }, 100)
         },
         function(){
           $(this).find('.slideDiv').hide('slide', { direction: 'left' }, 100)
         }
       )
     })
    

    And yes, The hoverIntent plugin is nice :P

    0 讨论(0)
  • 2021-01-03 05:23

    Use the hoverIntent plugin. This avoids anything being shown if the user simply passes the mouse over the elements, and avoids an unsightly chain of animations.

    0 讨论(0)
提交回复
热议问题