Untitled
By: a guest | Mar 21st, 2010 | Syntax:
JavaScript | Size: 1.40 KB | Hits: 77 | Expires: Never
$(document).ready(function(){
var currentPosition = 0;
var slideWidth = 560;
var slides = $('.slide');
var numberOfSlides = slides.length;
var isMoving = 0;
// Remove scrollbar in JS
$('#slidesContainer').css('overflow', 'hidden');
// Wrap all .slides with #slideInner div
slides
.wrapAll('<div id="slideInner"></div>')
// Float left to display horizontally, readjust .slides width
.css({
'float' : 'left',
'width' : slideWidth
});
// Set #slideInner width equal to total width of all slides
$('#slideInner').css('width', slideWidth * numberOfSlides);
// Insert controls in the DOM
$('#slideshow')
.append('<span class="control" id="rightControl">Clicking moves right</span>');
// Create event listeners for .controls clicks
$('.control')
.bind('click', function(){
if(!isMoving){
move();
}
})
function move(){
isMoving=true;
currentPosition = currentPosition+1;
if(currentPosition == numberOfSlides){
currentPosition = currentPosition-numberOfSlides;
}
// Move slideInner using margin-left
$('#slideInner').animate({
'marginLeft' : slideWidth*(-currentPosition)
});
isMoving=false;
};
function autoMove(){
if(!isMoving){
move();
setTimeout(autoMove,2);
}
}
});