如何重置一个jQuery动画重新开始? [英] how to reset a jquery animation to start over?

查看:325
本文介绍了如何重置一个jQuery动画重新开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一段不错的代码,一些动画和一些click/hover事件,其中只有一小部分.我打算在多个html文档上使用它(这是一个游戏,您必须获得正确的答案并继续下一个问题),并在另一个带有整页滑块的html中一起构建(我不想加载DOM多个次,没有任何意义):尚未解决的问题是:如何在不实际重新加载代码的情况下重置代码?如何清除到目前为止的所有内容并重新开始? 我是一个初学者,在其他代码片段上构建了东西.我想这一定是那么简单和基本的事情,没人能回答...动画化以前完成的所有工作的做法是不好的:太多的东西以及绑定和取消绑定.

I have built a nice piece of code, some animation and some click/hover events, quite a small row of them. I intend to use it on multiple html-documents (it is a game, you have to get right answer and proceed with next question), built together in another html with full-page-slider (I don't want to load DOM multiple times, makes no sense): the unsolved question is: how to reset the code without actually reloading it? how to make it to clear everything so far and start over? I am a beginner, building stuff upon others snippets. I guess it must be something so easy and basic that nobody answered it... The stuff to animate back all what is done previously is no good: too much stuff and binding and unbinding.

推荐答案

我有一个动画,每次运行代码时都会保持位置不变.要修复它,我使用了:

I had an animation that was keeping the position each time the code ran. To fix it I used:

function(){ $('.target').removeAttr('style'); }

所以我的代码是这样的:

so my code was something like:

$('#target').animate({
  opacity: 'toggle',
  top: '+=100',
  }, 1000, function() {
  $('#target').removeAttr('style'); 
});

这篇关于如何重置一个jQuery动画重新开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆