Note that there are some explanatory texts on larger screens.

plurals
  1. POImage gallery, FadeOut and navigation in jQuery
    text
    copied!<p>I'm trying to create an image gallery, but I'm facing a little problem with navigation. The problem is following: Whenever picture finishes with fading out, the little button changes its color, but I want my little button to change itself as soon as the current image starts fading out, not when it has finished fading out.</p> <p>HTML:</p> <pre><code>&lt;div id="portfolio_cycler"&gt; &lt;img class="active" src="images/pic1.jpg" alt="picture 1" /&gt; &lt;img src="images/pic2.jpg" alt="picture 2" /&gt; &lt;img src="images/pic3.jpg" alt="picture 3" /&gt; &lt;img src="images/pic4.jpg" alt="picture 4" /&gt; &lt;img src="images/pic5.jpg" alt="picture 5" /&gt; &lt;/div&gt; </code></pre> <p>CSS:</p> <pre><code>#portfolio_cycler{ position:relative; left: 55px; top: 50px; } #portfolio_cycler img{ position:absolute;z-index:1 } #portfolio_cycler img.active{ z-index:3 } #buttons{ position:absolute; top: 490px; left: 55px; } </code></pre> <p>jQuery:</p> <pre><code>function cycleImages(){ var $active = $('#portfolio_cycler .active'); var $next = ($('#portfolio_cycler .active').next().length &gt; 0) ? $('#portfolio_cycler .active').next() : $('#portfolio_cycler img:first'); activ=$active.index(); // INDEX TRENUTNO AKTIVNOG ELEMENTA $next.css('z-index',2);//move the next image up the pile $("#buttons img").eq(activ).attr('src','images/button_active.png'); $active.fadeOut(1500,function(){//fade out the top image $active.css('z-index',1).show().removeClass('active');//reset the z-index and unhide the image $next.css('z-index',3).delay(4000).addClass('active');//make the next image the top one cycleImages() }); } $(document).ready(function(){ pic_number=$("#portfolio_cycler img").length; for (i=0;i&lt;pic_number;i++) { $("#buttons").append("&lt;a href='javascript:void(0)'&gt;&lt;img src='images/button.png' /&gt;&lt;/a&gt;"); } // run every 7s setTimeout('cycleImages()', 4000); }); </code></pre> <p>Since my question might be confusing to some, I want to achieve similar effect: <a href="http://static.dreamcss.com/wp-content/uploads/example/" rel="nofollow">http://static.dreamcss.com/wp-content/uploads/example/</a> You notice how the active button changes just before the current image starts to slide? I want to achieve same thing with my buttons here.</p>
 

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