jQuery 动画鼠标悬停/鼠标悬停保持下拉菜单可见
我正在尝试使用动画制作一个基本的下拉菜单,但遇到了一个问题,我似乎无法弄清楚如何在鼠标离开之前保持下拉部分打开。有没有一种简单的方法可以让它保持开放状态?我知道我所拥有的关于 .clickme mouseout 功能是完全错误的,因为它会相应地卸载菜单。
如果有人可以在这个特定的情况下提供帮助,我将非常感激。
$(document).ready(function() {
$('.clickme').mouseover(function() {
$('#slidebox').animate({
top: '+=160'
}, 200, 'easeOutQuad');
});
$('.clickme').mouseout(function(){
$('#slidebox').animate({
top: '-=160'
}, 200, 'easeOutQuad')
});
});
I'm trying to make a basic drop down menu with animate and am running into the issue where I can't seem to figure out how to keep the dropdown part open until the mouse leaves. Is there an easy way to tell this to stay open? I know what I have is completely wrong regarding the .clickme mouseout function since it will unload the menu accordingly.
If anyone can help in this specific instance, I would be super grateful.
$(document).ready(function() {
$('.clickme').mouseover(function() {
$('#slidebox').animate({
top: '+=160'
}, 200, 'easeOutQuad');
});
$('.clickme').mouseout(function(){
$('#slidebox').animate({
top: '-=160'
}, 200, 'easeOutQuad')
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可以让您在没有任何标记更改的情况下继续操作:
由于您的元素与父/子无关,因此更容易在菜单上放置绝对位置(无论如何,CSS 中都有
130px
),所以没有理由不这样做使用它具有绝对位置的事实。试一试,我在你的网站上进行了测试,似乎是我想要在菜单中出现的行为。This should get you going without any markup changes:
Since your elements aren't parent/child related, easier to put absolute positions on the menu (it has
130px
in the CSS anyway), so no reason not to use the fact it has an absolute position. Give it a shot, I tested against your site, seems to be the behavior I'd want in a menu.查看jquery的hoverIntent
Check out jquery hoverIntent