Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Change your JS to this markup:</p> <pre><code>$(window).load(function () { //start after HTML, images have loaded var InfiniteRotator = { init: function ($elem) { //initial fade-in time (in milliseconds) var initialFadeIn = 1000; //interval between items (in milliseconds) var itemInterval = 5000; //cross-fade time (in milliseconds) var fadeTime = 2500; //count number of items var numberOfItems = $elem.find('.rotating-item').length; //set current item var currentItem = 0; //show first item $elem.find('.rotating-item').eq(currentItem).fadeIn(initialFadeIn); //loop through the items var infiniteLoop = setInterval(function () { $elem.find('.rotating-item').eq(currentItem).fadeOut(fadeTime); if (currentItem == numberOfItems - 1) { currentItem = 0; } else { currentItem++; } $elem.find('.rotating-item').eq(currentItem).fadeIn(fadeTime); }, itemInterval); } }; $('.rotating-item-wrapper').each(function(idx, elem){ InfiniteRotator.init( $(elem) ); }); }); </code></pre> <p><br> Instead of calling <code>init</code> just once, I'm using a jQuery function to run the function for each occurence of the <strong>class</strong> <code>rotating-item-wrapper</code>. <br> The other important trick is to hand over the corresponding element as an attribute to the <code>init</code> function.</p> <pre><code> $('.rotating-item-wrapper').each(function(idx, elem){ InfiniteRotator.init( $(elem) ); }); </code></pre> <p>As you can see, I also changed the function body and replaced every occurence of: <code>$('.rotating-item')</code> with <code>$elem.find('.rotating-item')</code> to distinguish between rotators.</p> <p><br><br> Also instead of different IDs on your wrapper, it's better to use a class (in my example I used: <code>rotating-item-wrapper</code>, you need to change that, too, for the example to work!).</p>
    singulars
    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.
    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