Create a Simple Image Slide Show using jQuery

I have seen a lot of users requesting for simple jQuery scripts for SlideShows. I saw a couple of them, but the scripts assumed that the number of image tags has to be fixed beforehand.

I thought of making an attempt at a real simple SlideShow script using jQuery. Here’s what I came up with 5 lines of jQuery code. The images have been added to a ‘images’ folder kept at the root. The images has been defined in an array which can be retrieved from a server. For simplicity sake, I have harcoded the images paths, however the script functionality can adapt dynamically to the number of images in the array.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><head>    <title>Simple Slide Show with jQuery</title>    <script type='text/javascript'    src='http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js'>    </script>    <script type="text/javascript">        var imgs = [        'images/emo.jpg',        'images/icon068.gif',        'images/icon260.jpg'];        var cnt = imgs.length;

        $(function() {            setInterval(Slider, 3000);        });

        function Slider() {        $('#imageSlide').fadeOut("slow", function() {           $(this).attr('src', imgs[(imgs.length++) % cnt]).fadeIn("slow");        });        }</script></head><body>    <img id="imageSlide" alt="" src="" /></body></html>

The code is not perfect but will give you an idea of how to extend this sample to suit your own requirements. You can see a Live Demo here.

Share:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Twitthis
This entry was posted in jQuery, Syndicated. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree