Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I synchronize two or more animations on the same page?
    primarykey
    data
    text
    <p>I guess my problem is not so much about keeping the animations in synch as it is keeping them from screwing up each other.</p> <p>I have two animations, on the same page within two saparate <code>document.ready</code> method. One of them fades in and fades out 3 images (belonging to the css class <code>g_img</code>) cyclically, and the other slides in and out three other images (belonging to the class <code>slogans</code>) also cyclically. Each of the functions that run these respective animations work fine just as intended when included within the <code>document.ready</code> function seperately but when I include them together as in the code presented below, they start behaving weird.<br> For example, one of them is animated in the sequence <code>1,2,2,1,3,2,1,3,2,1,3,2...</code> instead of the normal <code>1,2,3,1,2,3...</code> Even when I placed the animations in the same <code>document.ready</code> functions, I got something similar to the above. How can I fix this?</p> <p>Ps: I just uploaded the page which is still under construction to the following url <a href="http://mygeneric.info/green/index.html" rel="nofollow">http://mygeneric.info/green/index.html</a> so you can actually visualize what's going on. Please note that the page doesn't display as intended on firefox. Still need to work on that. Use any browser but firefox.</p> <pre><code>&lt;script type = "text/javascript"&gt; $(document).ready(function() { //First image in non js compliant browsers is by default displayed. //Hide it for compliant browsers $("#green_car").hide; //Do same for the first slogan(smart business). //Smaart business is positioned to be displayed for non js browsers. $(".slogans").hide(); $("#smart_business").css("left","245px"); (function($) { //The fade in out function. $.fn.fader = function() { var elements = this; l = elements.length; i = 0; function execute() { var current = $(elements[i]); i = (i + 1) % l; current .fadeIn(1000) .delay(8000) .fadeOut(1000,execute); } execute(); //Run the function. return this; //Making this available again to the outer function. }; })(jQuery); $(".g_img").fader(); }); &lt;/script&gt; &lt;script type = "text/javascript"&gt; $(document).ready(function() { //Do same for the first slogan(smart business). //Smaart business is positioned to be displayed for non js browsers. $(".slogans").hide(); $("#smart_business").css("left","245px"); (function($) { //The slide in out function. $.fn.slider = function() { var elements1 = this; l = elements1.length; i = 0; function execute1() { var current1 = $(elements1[i]); i = (i + 1) % l; current1 .fadeIn(100) .animate({'marginLeft' : '-=240px'},500) .delay(8000) .animate({'marginLeft' : '+=240px'},500) .fadeOut(100,execute1); } execute1(); //Run the function. return this; //Making this available again to the outer function }; })(jQuery); $(".slogans").slider(); }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload