使用slideup、向下滑动下拉菜单的jquery效果
我有一个下拉菜单,工作正常,但我想添加一些 jquery 效果,如动画、向上滑动、向下,
目前我使用可见性隐藏和隐藏。可见以显示 ul ,我如何对其使用其他效果,下面是代码:
<script type="text/javascript">
$(document).ready(function () {
$('.ul-links > li').bind('mouseover', openSubMenu);
$('.ul-links > li').bind('mouseout', closeSubMenu);
function openSubMenu() {
$(this).find('ul').css('visibility', 'visible');
};
function closeSubMenu() {
$(this).find('ul').css('visibility', 'hidden');
}; });
</script>
我尝试使用 :$('ul', this).slideDown(100); $('ul', this).slideUp(100);
没有成功 css:
.quiklinks .ul-links li ul
{
position:absolute;
visibility: hidden;
margin: 0px;
padding-top:0px;
z-index: 1000;
top: 42px;
left:0px;
}
任何帮助将不胜感激
I have got a drop down menu which works fine but i want to add some jquery effects like animation , slideup, down ,
currently i m using visiblity hidden & visible to show the ul , how can i use other effect on it , below is the code :
<script type="text/javascript">
$(document).ready(function () {
$('.ul-links > li').bind('mouseover', openSubMenu);
$('.ul-links > li').bind('mouseout', closeSubMenu);
function openSubMenu() {
$(this).find('ul').css('visibility', 'visible');
};
function closeSubMenu() {
$(this).find('ul').css('visibility', 'hidden');
}; });
</script>
I tried using :$('ul', this).slideDown(100); $('ul', this).slideUp(100);
with no success
css:
.quiklinks .ul-links li ul
{
position:absolute;
visibility: hidden;
margin: 0px;
padding-top:0px;
z-index: 1000;
top: 42px;
left:0px;
}
Any help will be highly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
.animate()
函数而不是.css()
函数:可以在此处找到
.animate()
的文档: http://api.jquery.com/animate/还有一些预先制作的动画:
这是一个使用的jsfiddle
.slideToggle()
和.fadeToggle()
: http: //jsfiddle.net/jasper/wFrpe/You can use the
.animate()
function rather than the.css()
function:Documentation for
.animate()
can be found here: http://api.jquery.com/animate/There are some pre-made animations as well:
Here is a jsfiddle for using
.slideToggle()
and.fadeToggle()
: http://jsfiddle.net/jasper/wFrpe/您可以使用
.slideToggle()
或.fadeToggle()
。可以通过组合多个这些函数来实现高级效果,也可以使用 jQuery 动画插件以获得额外的效果。我还使用
.hover()
简化了您的事件绑定,我注意到您还在样式表中使用
visibility:hidden;
。您应该删除它,因为它与 jQuery 使用显示样式修改元素是否可见的方式冲突。您可以通过调用 hide() 来实现:
额外提示:
使用动画时,始终包含
.stop(true, true)
在它们之前,否则如果用户在上一个动画完成之前与其交互多次,您将会出现怪癖。You can use
.slideToggle()
or.fadeToggle()
. Advanced effects can be achieved by combining several of these functions, or you can use a jQuery animation plugin for additional effects.I also simplified your event binding by using
.hover()
I noticed you are also using
visibility:hidden;
in your stylesheet. You should remove this, as it conflicts with the way jQuery uses the display style to modify whether an element can be seen.You can do it by calling a hide() instead:
BONUS TIP:
When using animations, always include
.stop(true, true)
before them, otherwise you will have quirks if the user interact with it many times before the previous animation has completed.