简单的jQuery悬停向下滑动,反向向上滑动?
我有以下简单的向下滑动悬停菜单。
$(function(){
$('.sub-menu').hide();
$('.menu-item').hover(
function () {
var target = $(this).children('ul');
$.browser.msie ? target.show() : target.slideDown(150);
},
function () {
var target = $(this).children('ul')
$.browser.msie ? target.hide() : target.slideUp(150);
}
);
});
当您将鼠标悬停在 .menu-item 上时,它会向下滑动 .sub-menu,并在您离开时向上滑动,完美。
当您将鼠标悬停在 .menu-item 上时,我需要它向上滑动 .sub-menu,反之亦然。
我已经完成了交换 SlideUp 和 SlideDown 的明显操作,但它似乎不起作用。
有什么想法吗?
如果可以的话非常感谢:)
I have the following simple slide down hover menu.
$(function(){
$('.sub-menu').hide();
$('.menu-item').hover(
function () {
var target = $(this).children('ul');
$.browser.msie ? target.show() : target.slideDown(150);
},
function () {
var target = $(this).children('ul')
$.browser.msie ? target.hide() : target.slideUp(150);
}
);
});
It slides down .sub-menu as you hover over .menu-item and slides back up when you leave, perfect.
I need it to slide up .sub-menu when you hover over .menu-item, vise versa to the above really..
I've done the obvious of swapping the slideUp and slideDown but it doesn't seem to work.
Any ideas?
Many thanks if you can :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该可以工作,尽管没有更多代码我无法测试它。
基本上我假设 .sub-menu 已经显示,所以当您将鼠标悬停在 .
menu-item
上时,您想隐藏它,对吗?我所做的更改是:我交换了两个函数并删除了开头的 $('.sub-menu').hide(); 。它在实际滑动之前不需要隐藏。
编辑:处理您的最新示例。
在这里查看: http://jsfiddle.net/GwBuj/3/
我所做的是:
#button
和#slider
更改为类(
.button
和.slider
)更改了
.slider
CSS 以允许多个按钮(你有它
绝对定位,不会
允许您看到其他)
按钮
你认为它有效
Should work, though I can't test it without more code.
Basically I'm assuming
.sub-menu
is already showing, so when you hover over .menu-item
you want to hide it, correct?All that I changed was: I swapped around the two functions and removed the
$('.sub-menu').hide();
that was at the beginning. It doesn't need hiding before it actually slides up.Edit: Working on your latest example.
Check it out here: http://jsfiddle.net/GwBuj/3/
What I did is:
#button
and#slider
toclasses (
.button
and.slider
)changed
.slider
CSS to allow formultiple buttons (You had it
positioned absolutely which wouldn't
allow you to see the others)
buttons
you that it works