View Full Version : jQuery How to loop an image slider

12-15-2010, 03:23 AM
I'm having a little bit of trouble with an image slider I am doing. I need it to loop to the beginning of the slide show when it reaches the end of the images

Here is my 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">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Twin Tiers Technologies - Image Slider</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<script src="jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="scripts.js" type="text/javascript"></script>

<div id="wrapper">
<div id="container">
<div id="mask">
<div id="slider">
<div id="images">
<img src="images/web.jpg" alt="Websites" />
<img src="images/mims.jpg" alt="Mortuary Information Management System" />
<img src="images/cims.jpg" alt="Cremetory Information Managment System" />
<img src="images/motv.jpg" alt="Memories On TV" />
<img src="images/web-casting.jpg" alt="Web Casting" />
<img src="images/support.jpg" alt="Support" />
<img src="images/arrow-back.png" id="back" />
<img src="images/arrow-forward.png" id="forward" />


Here is my CSS

@charset "UTF-8";
/* CSS Document */

width: 902px;
margin: 200px auto;

width: 861px;
height: 225px;
margin: 0 auto;
background-repeat: no-repeat;

width: 731px;
height: 225px;
margin: 20px auto;
overflow: hidden;

width: 2000px;

#slider img{
float: left;
padding: 5px;

float: left;
position: relative;
top: -140px;

float: right;
position: relative;
top: -140px;

position: relative;
float: left;

Finally my script:

// JavaScript Document

$(document).ready(function () {

$('#back').click(function (){

$('#images').animate({"left": "+=757px"}, 1000);

$('#forward').click(function () {

$('#images').animate({"left": "-=757px"}, 1000);

var $next = $active.next().length ? $active.next()
: $('#slideshow IMG:first');



Any suggestions?

12-15-2010, 02:58 PM

Try the attached instead.

No framework used.

Demo: here (http://www.javascript-demos.com/FreeSample.html)

12-15-2010, 05:45 PM
...or here's an endless looping slider tutorial (http://www.simonbattersby.com/blog/jquery-endless-slider/) I wrote.

12-15-2010, 06:01 PM
I’d suggest the cycle plugin (http://jquery.malsup.com/cycle/). It’s the best.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum