简体   繁体   English

jQuery backgroundcolor更改(.animate或.css)重新启动后只能工作一次吗?

[英]JQuery backgroundcolor changes (either .animate or .css) only work once after restart?

Hi everyone I've got a huge issue that I don't quite understand why it's happening. 大家好,我遇到了一个很大的问题,我不太明白为什么会这样。

The thing is, I got the jquery plugin jquery.color so that I could change 4 div's color alternately each 6 seconds so that when the first one is white, the others are black, when the second is white the others are black and so forth. 问题是,我得到了jquery插件jquery.color,以便可以每6秒交替更改4 div的颜色,以便第一个为白色时,其他为黑色,第二个为白色时,其他则为黑色,依此类推。 。

When I started out programming it everything was working and I thought I was making progress but I tried it again and nothing... I decided that maybe it was the jquery color plugin's fault so I decided to give jquery UI plugin a go. 当我开始编程时,一切都工作正常,我以为自己正在取得进步,但我又尝试了一次,但是没有任何事情……我认为这可能是jquery color插件的问题,所以我决定尝试一下jquery UI插件。 I emptied the caches and restarted the mac, tried the "new" plugin and it was working again so I started to program a little more, tried it again and BAM same thing happens... 我清空了缓存并重新启动了Mac,尝试了“新”插件,它又开始工作了,所以我开始进行更多编程,再次尝试,BAM发生了同样的事情...

The weird thing is that the exact same code works after a restart but does not work a second time... 奇怪的是,完全相同的代码在重新启动后可以使用,但是第二次不能使用...

I've got the following jquery plugins on use: jquery.urlrewrite, jquery.easytabs, jquery.ae.image.resize and of course jquery-ui. 我使用了以下jquery插件:jquery.urlrewrite,jquery.easytabs,jquery.ae.image.resize和jquery-ui。

The small snippet of .JS code that I am using for testing purposes is: 我用于测试目的的.JS代码的小片段是:

var intervalo = window.setInterval(caneco, 6000);

function caneco(){


$("#triangulo").animate({
top: "120px"
}, 1000 );

$("#juntaimg").animate({
left: "-451px"
}, 1000 );

$("link1").animate({
  'background-color': "black"
}, 1000);


}

Weirdest of all, all other animations aside from backgroundColor changes work perfectly and everytime... 最奇怪的是,除backgroundColor更改之外的所有其他动画每次都能完美运行。

Can anyone help me out?? 谁能帮我吗?? Please?? 请??

Well for anyone that has this problem it was due to a conflict between the index.php and the update.php which was being loaded using jquery's .load into a div. 对于任何有此问题的人来说,这都是由于使用jquery的.load加载到div中的index.php和update.php之间存在冲突引起的。 Since I developed everything independently and afterwards joined it I had jquery 1.7.1 being loaded two times, had some php scripts being loaded twice and so on... So basically I solved it all by using a restrained .load like this: 因为我独立开发了所有东西,然后加入了它,所以我将jquery 1.7.1加载了两次,将一些php脚本加载了两次,依此类推...因此,基本上,我通过使用如下约束的.load来解决了所有问题:

$("#finalcontainer").load("updates.php #initialcontainer");

and then I just moved all the css of that page to the index css file (I know I should have done it already but that bug was killing me!) and also I moved all the .js animations of updates.php to the index.php. 然后我只是将该页面的所有css移到了索引css文件中(我知道我应该已经做过,但是那个虫子使我丧命了!),而且我还将updates.php的所有.js动画都移到了索引中。的PHP。

So that's how I squashed my bug. 因此,这就是我压缩错误的方式。 And mainly it was my fault all along... 一直以来主要是我的错...

Here's a fully working jsFiddle: 这是一个完全可以使用的jsFiddle:

I corrected / changed it a bit (eg intervals and the animation descriptions) but that should not be a major thing - if it works, your code should work. 我已对其进行了一些更正/更改(例如,间隔和动画说明),但这并不是一件大事-如果它可以工作,则您的代码应该可以工作。

If this works for you and your local version doesn't, try making a small example like this - just include the jQuery and jQuery UI and the code from the jsFiddle and see if that works. 如果这对您有效,而您的本地版本不起作用,请尝试制作一个像这样的小示例-仅包括jQuery和jQuery UI以及jsFiddle中的代码,然后看看是否可行。 If it does, it's probably some typo / missed tag or any other syntax error that's making it not work. 如果是这样,则可能是某些拼写错误/未命中标记或任何其他语法错误导致其无法正常工作。

Btw, you probably want setTimeout instead of setInterval , as the latter will repeat the call every n milliseconds, while setTimeout runs it once. 顺便说一句,您可能希望使用setTimeout而不是setInterval ,因为后者将每n毫秒重复一次调用,而setTimeout将运行一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM