替换.toggle(在jQuery 1.9 [英] Replacement for .toggle( in jQuery 1.9
本文介绍了替换.toggle(在jQuery 1.9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现了不同的替代方法,在这里为jQuery 1.9切换,但我不能在这里的工作:
I found different alternatives to toggle here for jQuery 1.9, but I don't get it to work im my case here:
$('.thumb.flip').toggle(
function () {
$(this).find('.thumb-wrapper').addClass('flipStop');
},
function () {
$(this).find('.thumb-wrapper').removeClass('flipStop flipIt');
}
);
推荐答案
您可以给.flip一个数据属性
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);
});
或者您可以使用elseif
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');
}
});
这篇关于替换.toggle(在jQuery 1.9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文