...

View Full Version : jQuery How to loop an image slider



ExplosiveHippo
12-15-2010, 02:23 AM
Hello,
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">
<head>
<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>
</head>

<body>
<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" />
</div>
</div>
</div>
</div>
<img src="images/arrow-back.png" id="back" />
<img src="images/arrow-forward.png" id="forward" />
</div>

</body>
</html>

Here is my CSS

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

#wrapper{
width: 902px;
margin: 200px auto;
}

#container{
width: 861px;
height: 225px;
margin: 0 auto;
background-image:url(images/slider-bg.png);
background-repeat: no-repeat;
}

#mask{
width: 731px;
height: 225px;
margin: 20px auto;
overflow: hidden;
}

#slider{
width: 2000px;
}

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

#back{
float: left;
position: relative;
top: -140px;
}

#forward{
float: right;
position: relative;
top: -140px;
}

#images{
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?

Sciliano
12-15-2010, 01:58 PM
ExplosiveHippo:

Try the attached instead.

No framework used.

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

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

VIPStephan
12-15-2010, 05: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