消失后,Jquery下拉列表中的类删除 [英] Jquery dropdown remove class after disappears
问题描述
我有一个下拉列表的代码,我需要删除#products上的'hovered'类,在菜单向上滑动并且已经消失。我该如何做?目前,它直接消失在onmouseout
感谢任何帮助解决这个! :$)
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $产品div ul')。css({'margin-top':' - '+ divTop +'px','float':'left'});
$('#products> a,#products div')。hover(function(){
$('#products')。addClass('hovered');
$('#products div ul' .stop()。animate({'margin-top':'0'});
},function(){
$('#products')。removeClass('hovered');
$('#products div ul')。show()。stop()。animate({'margin-top':' - '+ divTop +'px'});
});
});
您可以调用 .removeClass()
.jquery.com / animate /rel =nofollow noreferrer> .animate()
回调,如下所示:
$(function(){
var divTop = 168;
$('#products div ul')。css({'margin-顶部':' - '+ divTop +'px','float':'left'});
$('#products> a,#products div')。hover ){
$('#products')。addClass('hovered');
$('#products div ul')。show()。stop()。animate({'margin-top ':'0'});
},function(){
$('#products div ul')show()stop()。animate({'margin-top' - '+ divTop +'px'},function(){
$('#products')。removeClass('hovered');
});
});
});
I have this code for a dropdown and I need to remove the class 'hovered' on '#products' after the menu slides up and has disappeared. How do I do this? Currently it disappears straight away onmouseout
Thanksfor any help in resolving this! :-)
$(function() {
var divTop = 168;
$('#products div ul').css({'margin-top': '-' + divTop + 'px','float':'left'});
$('#products > a,#products div').hover(function(){
$('#products').addClass('hovered');
$('#products div ul').show().stop().animate({'margin-top': '0'});
},function(){
$('#products').removeClass('hovered');
$('#products div ul').show().stop().animate({'margin-top': '-' + divTop + 'px'});
});
});
You can call .removeClass()
in the .animate()
callback, like this:
$(function() {
var divTop = 168;
$('#products div ul').css({'margin-top': '-' + divTop + 'px','float':'left'});
$('#products > a,#products div').hover(function(){
$('#products').addClass('hovered');
$('#products div ul').show().stop().animate({'margin-top': '0'});
},function(){
$('#products div ul').show().stop().animate({'margin-top': '-' + divTop + 'px'}, function() {
$('#products').removeClass('hovered');
});
});
});
这篇关于消失后,Jquery下拉列表中的类删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!