Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to automate carousel
    primarykey
    data
    text
    <p>I am creating my own carousel which moves one step to the left or right depending on what button was clicked. That part of the code works as expected hence i have not included it here</p> <p>What i am unable to accomplish is to automate or rotate the carousel when the page loads up. That is after every 4 or 5 seconds the current active element should move to the next.</p> <p>The code below shows my current attempt.</p> <pre><code>$('.promo-nav').show(); function rotate() { var showid = 0; if(!$(this).parent().parent().hasClass('active')){ id = $(this).parent('li').index(); $(this).parent().parent().children('li.active').removeClass('active'); $(this).parent().addClass('active'); $(this).parent().parent().parent().parent().parent() .children('.promo-carousel-content').css({'display':'none'}) .eq(id).css({'display':'block'}); } } window.setTimeout(rotate, 400); //css .promo-carousel {display: block;} .content {display: none;} .content.first {display: block;} //markup &lt;div class="grid_4"&gt; &lt;div class="promo-carousel"&gt; &lt;div class="content first"&gt; //some content &lt;/div&gt; &lt;/div&gt; &lt;div class="promo-nav"&gt; &lt;div&gt; &lt;div class="prev"&gt; &lt;a href="#"&gt;&lt;span class="hide"&gt;previous&lt;/span&gt;&lt;/a&gt; &lt;/div&gt; &lt;ul&gt; &lt;li class="active"&gt;&lt;a href="#"&gt;&lt;span class=""&gt;first&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;span class=""&gt;second&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="circle"&gt;&lt;a href="#"&gt;&lt;span class=""&gt;third&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="circle"&gt;&lt;a href="#"&gt;&lt;span class=""&gt;fourth&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div class="next"&gt; &lt;a href="#" class=""&gt;&lt;span class="hide"&gt;next&lt;/span&gt;&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
    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.
 

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