SlideUp and Slidedown on hover menu

。_饼干妹妹 提交于 2019-12-13 06:14:06

问题


I am having a menu which will show a slider on hover(). I have written it like this

$(".menu2").hover(function ()
{
 $(".slider").slideDown(500);
  $(".slider").css('display','block');      
},
    function () {   
    $(".slider").slideUp(500);      
 //$('.slider').css("display","none");

});

This shows the slider.(I like to use slideDown() and slideUp() to look good). When I move my cursor to the slider it goes back to the display:none state. So I tried this

 $(".sliderHolder").hover(function ()
{
  $(".slider").css('display','block');              
},
    function () {

 $(".slider").slideUp(500);

 });

});

This sets my slider to display:none state after I move my cursor from the menu. Is there an easier way to do this though?


回答1:


Are you expecting like

http://jsfiddle.net/jUraw/1369/

      <ul id="nav">
        <li><a href="home.html"><span>M</span>enu</a>
            <ul>
                <li><a href="fashion.html"><span>F</span>ashion</a></li>
                <li><a href="about-us.html"><span>A</span>bout <span>U</span>s</a></li>
                <li><a href="find-us.html"><span>F</span>ind <span>U</span>s</a></li>
                <li class="underline"><a href="http://www.bellissimafashions.com/blog/"><span>B</span>log</a></li>
            </ul>
        </li>    
    </ul>


$(document).ready(function (){
    var t = null;
    $('#nav li').hover(function(){
        var that = this;
        t = setTimeout(function(){
            $('ul', that).slideDown(200);
            t = null;
        }, 300);
    }, function(){
        if (t){
            clearTimeout(t);
            t = null;
        }
        else
            $('#nav li ul').slideUp(200);
    });
});


来源:https://stackoverflow.com/questions/16058900/slideup-and-slidedown-on-hover-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!