jQuery toggle animation doesn't work on new jQuery

匆匆过客 提交于 2019-11-27 08:26:51

问题


I have problem with this toggle on jQuery 1.8.2 i works but on 1.11.0 no. Can you help me what is wrong?

$('.open').toggle(function () {
    $('.obj').animate({
        top: "0"
    }, 500);
},function () {
    $('.obj').animate({
        top: "-8%",
    }, 500);
});

回答1:


As mentioned in the comments you will need to do this using the click method. Here is an example that uses the element's data to store the state:

$('.open').on('click', function(){
    var isToggled = $(this).data('isToggled');
    if(isToggled){
        $('.obj').animate({
            top: "-8%",
        }, 500);
    } else {
      $('.obj').animate({
            top: "0"
        }, 500);
    } 

    $(this).data('isToggled', !isToggled)
});


来源:https://stackoverflow.com/questions/21391620/jquery-toggle-animation-doesnt-work-on-new-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!