Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
替换.toggle(在jQuery 1.9中_Jquery_Click_Toggle - Fatal编程技术网

替换.toggle(在jQuery 1.9中

替换.toggle(在jQuery 1.9中,jquery,click,toggle,Jquery,Click,Toggle,我在jQuery 1.9中找到了不同的切换选项,但在我的案例中无法实现: $('.thumb.flip').toggle( function () { $(this).find('.thumb-wrapper').addClass('flipStop'); }, function () { $(this).find('.thumb-wrapper').removeClass('flipStop flipIt'); } ); 您可以使用“单击”事件,然后使用“:visible”选中(如果元素此时

我在jQuery 1.9中找到了不同的切换选项,但在我的案例中无法实现:

$('.thumb.flip').toggle(
function () {
$(this).find('.thumb-wrapper').addClass('flipStop');
},
function () {
$(this).find('.thumb-wrapper').removeClass('flipStop flipIt');
}
);
您可以使用“单击”事件,然后使用“:visible”选中(如果元素此时可见):

  • 如果元素可见-通过添加类似于代码的类来隐藏它,或者只需:~.hide()

  • 如果元素不可见-添加/删除类或使用:~.show()


您可以给.翻转数据属性

<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);
});

如果您想要相同的代码工作,请查看迁移项目,否则请使用类似于您的代码的替代代码,因为它似乎有逻辑问题,或者缺少某些内容……flipIt的意义是什么?您从未在开始时添加过它,那么它为什么会出现呢?
$('.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');
    }
});