jQuery .click .animate向下移动,然后再向上移动

到目前为止,我设法做到这一点,所以它以120的增量向下移动,但我希望它上下,而不是上下……我希望我已经解释了这一点,所以“有人”会理解。

 $(document).ready(function() { $('#footertab').click(function() { $('#footer').animate({ bottom: '-=120' }, 1000, function() { // Animation complete. }); }); });  

如果我做对了,你就想切换页脚的位置。 这可以使用.toggle() – 函数完成:

 $(document).ready(function() { $('#footertab').toggle(function() { $('#footer').animate({ bottom: '-=120' }, 1000); },function() { $('#footer').animate({ bottom: '+=120' }, 1000); }) }); 

你可以使用.toggle()

 $(function() { //shortcut for $(document).ready(function() { $('#footertab').toggle(function() { $('#footer').animate({ bottom: '-=120' }, 1000); }, function() { $('#footer').animate({ bottom: '+=120' }, 1000); }); }); 

通过使用.toggle() ,每次click事件都会在运行-=+=动画之间切换。 另请注意,如果没有执行任何操作,则无需包含动画回调,只需将其关闭即可。