Toggle animation?
I have this code:
$('.couch-hide').click(function() {
$(this).animate({right:0},1000, 'easeOutBounce');
});
I am trying to get it to toggle, so on first click, pop it out, then click again, and place it back inside. Would i need to set a variable as a tracker? To tell what stage it is at?
如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

评论(2)


Just save the original value somewhere, and remember to stop any in-progress animation before starting a new one. The animation routines will take care of the rest:
var panel = $('.couch-hide');
var originalPos = panel.css("right");
panel.toggle(function() {
$(this).stop().animate({right:0},1000, 'easeOutBounce');
},
function() {
$(this).stop().animate({right:originalPos},1000, 'easeOutBounce');
});
发布评论
需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。