问题
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