问题描述
我试图在没有动画的情况下切换元素的可见性,但要具有完整的功能,以便更改链接的文本以启动切换.
I'm trying to toggle an element's visibility without animation, but with a complete function so that I change the text of the link initiating the toggle.
jQuery('.toggle_tags').click(function(){
var elem = jQuery(this);
jQuery('#taglist').toggle({complete: function() {
if (jQuery(this).is(':visible')) {
elem.text('(Hide Tags)');
} else {
elem.text('(View Tags)');
}
},});
return false;
});
不幸的是,这仍在触发动画.没有任何参数,切换不会设置动画,但是即使只是通过一个函数或完整地传递完整函数(如上所述),我仍然可以获得动画.
Unfortunately this is still triggering animation. Without ANY params, toggle doesn't animate but even either by passing just a function or the complete function verbosely (as above), I still get animation.
有什么建议吗?
推荐答案
不要使用complete
函数.
没有参数,.toggle()
将同步运行,这意味着您可以在下一条语句中测试它的工作,知道它已经完成了,您可以使用:
Without parameters, .toggle()
will operate synchronously, meaning that you can just test what it did in the next statement, knowing that it will already have finished, you could use:
jQuery('#taglist').toggle();
if (jQuery('#taglist').is(':visible')) {
elem.text('(Hide Tags)');
} else {
elem.text('(View Tags)');
}
这篇关于jQuery toggle()没有动画但功能完整吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!