Replacement for .toggle( in jQuery 1.9 [closed]

余生颓废 提交于 2019-12-02 13:15:01

You can give .flip a data-attribute

<div class="thumb flip" data-clicked="0">

$('.thumb.flip').click(function () {
    var data = $(this).data('clicked'), $descendant=$(this).find('.thumb-wrapper');
    if (data) {
        $descendant.removeClass('flipStop flipIt');
    } else {
        $descendant.addClass('flipStop');
    }
    data == 0 ? $(this).data('clicked', 1) : $(this).data('clicked', 0);
});

Or you can use elseif

$('.thumb.flip').click(function () {
    if ($(this).find('.thumb-wrapper').hasClass('flipstop')) {
        $(this).find('.thumb-wrapper').removeClass('flipStop flipIt');
    } else {
        $(this).find('.thumb-wrapper').addClass('flipStop');
    }
});

You can use "click" event and then check using ":visible" (if the element is visible at the moment):

  • if the element is visible - hide it by adding a class like your code or just: ~.hide()

  • if the element isn't visible - add/remove class or use: ~.show()

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