消失后,Jquery下拉列表中的类删除 [英] Jquery dropdown remove class after disappears

查看:96
本文介绍了消失后,Jquery下拉列表中的类删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表的代码,我需要删除#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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆