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.
Update: There is a updated version of this article at Simple Image SlideShow using jQuery
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.
Update: There is a updated version of this article at Simple Image SlideShow using jQuery
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>
No comments:
Post a Comment