jQuery切换动画不适用于新jQuery [英] jQuery toggle animation doesn't work on new jQuery
本文介绍了jQuery切换动画不适用于新jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在jQuery 1.8.2上进行此切换时遇到问题,但在1.11.0上却可以.你能帮我怎么了吗?
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);
});
推荐答案
如注释中所述,您将需要使用click方法执行此操作.这是一个使用元素的数据存储状态的示例:
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)
});
这篇关于jQuery切换动画不适用于新jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文