Simple Autoslide


/ Published in: jQuery
Save to your folder(s)

This goes through the specified div, and finds a div with the class of current. It then removes the class from that div, and adds it onto the next one. Note: Through CSS make the current class with a display block, and the slide class with a display none.


Copy this code and paste it in your HTML
  1. jQuery(document).ready(function($) {
  2. setInterval("autoSlide()", 10000);
  3. });
  4.  
  5. function autoSlide(){
  6. var nextidx = (parseInt(jQuery("#slideshow .current").index()+1) == jQuery("#slideshow .slide").length) ? 0 : parseInt(jQuery("#slideshow .current").index()+1);
  7. jQuery("#slideshow .current").fadeOut('slow', function(){
  8. jQuery(this).removeClass('current');
  9. jQuery("#slideshow .slide").eq(nextidx).fadeIn('slow', function(){
  10. jQuery(this).addClass('current');
  11. });
  12. });
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.