jQuery Looped Slider Tutorial

2009 June 18
by Raymond Selda

Today we’re going to use Nathan Searles’ jQuery loopedSlider, a plugin made for jQuery that solves a simple problem, the looping of slide content. It was created to be easy to implement, smooth and most of all end the “content rewind” that most other content sliders suffer from.

This is going to be a quick and easy tutorial. You can just copy and paste the code and have yourself a looping slider in minutes. You can view a working demo and feel free to download the complete source files.

Markup

<!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" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

	<title>loopedSlider jQuery Plugin</title>

	<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="loopedslider.js" type="text/javascript" charset="utf-8"></script>

	<style type="text/css" media="screen">	

	</style>
</head>

<body>
<div id="loopedSlider">
	<div class="container">
		<div class="slides">
			<div><img src="image-01.jpg" width="600" height="393" alt="First Image" /></div>
			<div><img src="image-02.jpg" width="600" height="393" alt="Second Image" /></div>
			<div><img src="image-03.jpg" width="600" height="393" alt="Third Image" /></div>
			<div><img src="image-04.jpg" width="600" height="393" alt="Fourth Image" /></div>
		</div>
	</div>
	<a href="#" class="previous">previous</a>
	<a href="#" class="next">next</a>
	<ul class="pagination">
		<li><a href="#">1</a></li>
		<li><a href="#">2</a></li>
		<li><a href="#">3</a></li>
		<li><a href="#">4</a></li>
	</ul>
</div>
</body>
</html>

Styles (CSS)

/*
 * Required
*/
.container { width:600px; height:393px; overflow:hidden; position:relative; cursor:pointer; }
.slides { position:absolute; top:0; left:0; }
.slides div { position:absolute; top:0; width:600px; display:none; }
/*
 * Optional
*/
#loopedSlider,#newsSlider { margin:0 auto; width:500px; position:relative; clear:both; }
ul.pagination { list-style:none; padding:0; margin:0; }
ul.pagination li  { float:left; }
ul.pagination li a { padding:2px 4px; }
ul.pagination li.active a { background:blue; color:white; }

Power Up The Slider

This time we’re going to initialize the plugin from the bottom section of our document in order to load our content first before the calling our plugin.

<script type="text/javascript" charset="utf-8">
	$(function(){
		$('#loopedSlider').loopedSlider();
	});
</script>
</body>
</html>

Autostart the slider:

<script type="text/javascript" charset="utf-8">
	$(function(){
		$('#loopedSlider').loopedSlider({
			autoStart: 3000
		});
	});
</script>
</body>
</html>

Initialize multiple sliders:

<script type="text/javascript" charset="utf-8">
	$(function(){
		$('#loopedSlider').loopedSlider({
			autoStart: 3000
		});
		$('#anotherSlider').loopedSlider({
			autoHeight: 400
		});
	});
</script>
</body>
</html>

View Demo for both autostart and multiple sliders

Conclusion

I really like the simplicity of this plugin and I think I’m going to use this in my future projects. How about you? Have you ever used jQuery loopedSlider before? What other jQuery sliders would you recommend? Thanks for reading.

44 Responses leave one →
  1. June 29, 2009

    hi there!

    I trying to implement this nice jquery slider into my WP functions.php file. Clould you help me?

  2. June 29, 2009

    Sure Sergio. I also implemented this slider in my homepage and put the javascript calls in my functions file. Do you like that approach?

  3. June 29, 2009

    Sure. I would like to have it in my home page. I don’t speak english very well (i’m from spain) but, basically my doubts are:

    - Are there any conflicts with other jquery calls from other plugins in my theme framework?

    I understand the main concept and is easy to get it work in plain html, but i make some errors implementing in WP, it becomes more complex. Sintaxis…

    Could you share your code for me to understand how it is written in functions file and aply in future projects?

    thanks.

  4. June 29, 2009

    This will not get in any conflict with the other plugins.

    Actually you can make this work without needing a functions file.

    But here’s what I did:
    – Create a new page for your loopedslider
    – Open up functions file and place this code:


    function loopedslider_js()
    {
    if (is_page(postidhere)) { //If page is custom static homepage ?>
    <script language="javascript" src="<?php bloginfo('template_url'); ?>/js/loopedslider.js" type="text/javascript"></script>
    <script type="text/javascript" charset="utf-8">
    $(function(){
    $('#loopedSlider').loopedSlider({
    autoStart: 4000
    });
    });
    </script>
    <?php }
    }
    add_action('wp_head', 'loopedslider_js');

    This will check if it’s the page where you want to show the loopedslider so the call won’t show up in every page.

    Good luck Sergio

  5. June 30, 2009

    Greatfull! Thanks, I almost finished with it. Only remains a problem with the path “bloginfo” to my images. I use hybrid framework theme.

  6. Nortehanon permalink
    July 2, 2009

    Hello po!
    Sorry if this is a dumb question but I really have zero knowledge in techie stuff such as this. But I am trying to put up a blog in WordPress on my own. I admire your knowledge on these things and the slide you made looks great that I aspire to one like that in front of my blog. My questions are, if I use the source code you have here and change your sample images into my images, will that already work? Do I have to tweak my css file? I would love to have it in my blog but I really don’t know how to integrate it.

    Thank you so very much, at magandang araw po.

  7. July 2, 2009

    Hi Nortehanon,

    There is no such thing as a dumb question. You do need to tweak the CSS file. You just need to change the width and height of .container and the width of .slides div depending on your image dimensions. Good luck and thanks for the comment.

  8. July 10, 2009

    hi-

    Curious to know how to get the images to link to outside URLs. Right now, the demo seems to show them working with the pagination (i.e., clicking on one image advances it to the other). I’d like to use the lower nav for pagination, but have the images link elsewhere. Thanks

  9. July 11, 2009

    Hi ed,

    I believe you just have to surround the images with anchor tags. You can have a look at my homepage for an example of what you’re saying. Hope that helps. Good luck.

  10. Alex permalink
    July 23, 2009

    Hi,

    I’m trying to make the transitions form one image to another to be faded instead of slide. Can you please tell me what do I need to change in this script.

    Thanks

  11. August 8, 2009

    I have autoslide on, and I’m trying to get it to fade instead of slide, as it rolls through the images. Having a very tough time with this.

    I have rearranged/added to the ‘next’ function, using snippets from the ‘fade’ function, and i got it to fade, but it won’t advance to the next image. I also got it to fade and advance, but it doesn’t reset when it gets to the end.

    Any input is appreciated.

  12. Gino Paulo permalink
    August 20, 2009

    Hi Raymond!

    Really good stuff you have here! I was just wondering how to get this to work within a post in wordpress.
    What exactly should I put into the custom field?? The header?? And where do I put the *.js files??

    I’ve been trying to figure this one out for weeks already! Hahaha! I do get along with HTML and CSS well but JS is just way too complex for me!

    Many thanks bro!
    Gino

  13. August 21, 2009

    You can see an example of this in my homepage (sliding portfolio images), but I didn’t use custom fields with that. I just created a custom page and assigned that as my homepage. You can just create a folder for JS and then place code in the head section. You can view my source code for the homepage for some ideas.

    I hope this helps.

  14. August 21, 2009

    Hi there thanks for the very nice plugin. I have one question, is there any cretin licensing, or restrictions?

  15. August 21, 2009

    For others that might have this question, this is how I got it to fade when it is autoscrolling through the images. Initially this caused it to not start over once it had reached the last slide, but it now functions correctly.

    case ‘next’:
    t = t+1;
    m = (-(t*w-w));
    current(t);
    if(o.autoHeight){autoHeight(t);}
    $(o.slides,obj).children().fadeOut(o.fadespeed, function(){
    $(o.slides,obj).css({left: m});
    $(o.slides,obj).children(‘:eq(‘+(s-1)+’)').css({left:s*w-w});
    $(o.slides,obj).children(‘:eq(0)’).css({left:0});
    if (t===s+1) {
    t = 1;
    m = (-(t*w-w));
    current(t);
    }
    if(t===s){$(o.slides,obj).children(‘:eq(0)’).css({left:(s*w)});}
    if(t===s-1){$(o.slides,obj).children(‘:eq(‘+(s-1)+’)').css({ position:’absolute’,left:-w});}

    $(o.slides,obj).children().fadeIn(o.fadespeed);
    u = false;
    });
    break;

  16. August 22, 2009

    I didn’t create that plugin. I think I have a link on my article pointing to the author of the plugin. :-)

  17. Eduardo permalink
    September 17, 2009

    Hi Raymond,
    Thanks for the Tutorial, its awesome!
    I have one question,
    Its possible to make all transitions with fade?

    Thanks!
    Eduardo

  18. September 20, 2009

    Thank you for this write-up.

    Is there any way to load the banners in a random order?

  19. October 3, 2009

    HI there thanks for the great tutorial but i was wondering if you would remove the clickable nature of the divs so that you could add things inside them such as images and text with multiple links?

  20. October 12, 2009

    Nice one mate. I have also added the link to your post in my Ultimate

    collection of top jQuery tutorials, tips-tricks and techniques to improve

    performance. Have a check below:

    http://technosiastic.wordpress.com/2009/09/24/collection-of-top-jquery-

    tutorials-tips-tricks-techniques-to-improve-performance/

  21. October 18, 2009

    How do I make links somewhere else on my site to change the picture order??? The HTML # isnt really working. Been trying to get this to work for hours now…

  22. Alan Earl permalink
    November 10, 2009

    Hello Raymon,

    Im not good yet at JQuery & i find your loopedCarousel
    very good… especially per items view.
    But it is limited to 6 children.

    How can i fix this limited to 3 children?

    Can u help … ty

  23. kax permalink
    November 13, 2009

    Hi
    What should I do if there is only one image in slider? It doesn’t work

  24. November 26, 2009

    Thank you so much for this beautiful plagin! I’ll use it in my future project!

  25. December 10, 2009

    Pre, thanks a bunch! Saved my ass!

  26. December 17, 2009

    Hello,

    I love this slider but have a request from a client to have the rewind feature taken out (when it gets to the last slide just stop). I’d like to use this slider but might have to use another if this cannot be achieved. Have any ideas?

    Thanks,

    Devin

    htttp://www.dlocc.com

  27. Manuel permalink
    January 7, 2010

    Hello together,

    i try tu use the bxSlider and the loopedslider plugin in a thickbox.
    unfortunatelly it doesn’t work correctly inside the thickbox. has anyone an idea what the problem could be? thanks for your help.

    manuel

  28. February 12, 2010

    i know this defeats the purpose of this script, but how do i make it not loop? i’ve already customized it to exactly how i want to look and don’t want to change to another script at this point. any help?

  29. March 7, 2010

    Hi :D
    I`m a beginner at this stuff. I`m trying to put a looped slider on my weebler but i can’t figure out how. I’ve been trying for countless hours and it just won`t work… Can you help?

  30. March 17, 2010

    Is there any reason why it would display a blank at the end of the sequence when there are only three images defined in the HTML? This only happens in Safari and IE8 so far.

    In all versions of Firefox it’s fine.

    Thanks.

  31. March 17, 2010

    Sorry… one more. How can I disable the ability to click on the image? I just want it to scroll without user interaction. Currently, I’m finding that a click will stop the autoscroll. Thanks again.

  32. Gina Alessia permalink
    March 17, 2010

    @Eric: your code works for fading instead of sliding but only for next button. Can you share the code for the left button?

    Cheers!

  33. Artee permalink
    June 4, 2010

    $(function(){
    $(‘#loopedSlider’).loopedSlider({
    autoStart: 6000,addPagination:true,containerClick:false
    });
    });

    NOW CONTAINER CLICK DOESNOT WORKING :)

    PS.
    Raymond, thx for tutorial !!!!

  34. Carlos permalink
    June 16, 2010

    Any idea how you make it change to a certain slide? Ie like pagination but using a different link?

  35. June 25, 2010

    Hi. I am using loopedcarousel, and found a problem. I have gone through the javascript file, but cannot seem to find the problem. The problem is that sometimes, when clicking the previous button, the slider shows up with blank slided. Any ideas please?

    Thanking you
    Tasneem

  36. heath permalink
    June 30, 2010

    Hi,

    Thanks for the great tutorial. Does anyone know of a way to add captions to images using this slider?

    Thank you!

  37. leo permalink
    July 23, 2010

    hi does any one know how to link the images in order when to click it take you to another page or site thank you very much in advanced for your help

  38. July 27, 2010

    If you want to link the images to different URL’s when you click on them you just need to change containerClick:true to containerClick:false. You’ll find this code near the end of the javascript file. After that just wrap the image in an anchor tag and you’re good to go!

    Great tut! Thanks!

  39. Mike permalink
    July 29, 2010

    Has anyone figured out how to use this without a height value on #container? Or to grab the longest entry’s height and use that?

Trackbacks and Pingbacks

  1. Jquery, looped et slider vont au bal | Orgied.com
  2. Ultimate collection of top jQuery tutorials, tips-tricks and techniques to improve performance « Technosiastic!
  3. 25 Very Detailed jQuery Image and Content Slider Tutorials |
  4. Ultimate collection of top jQuery tutorials, tips-tricks and techniques to improve performance
  5.   Moé Moé Rabu Layout Mark 5 GO!! by Moé Moé Rabu

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS