$(document).ready(function () {
//initialize carousel
carousel();
//Initialize thumbnail rotation
thumbnailLoop(0);
});
var slide_width;
var left_value;
function carousel() {
slide_width = $('.slidesContainer li').outerWidth();
left_value = slide_width * (-1);
var speed = 3000;
var run = setInterval('rotate(' + slide_width + ', ' + left_value + ')', speed);
//Move the last slide before the first slide
$('.slide:first').before($('.slide:last'));
//set the default item to the correct position
$('.slidesContainer ul').css({
'left': left_value
});
//Pause the slides on mouseenter. Start the carousel again on mouseout
$('.slidesContainer').hover(
function () {
clearInterval(run);
},
function () {
run = setInterval('rotate(' + slide_width + ', ' + left_value + ')', speed);
});
}
function rotate(s_width, l_value) {
//get the correct position
var left_indent = parseInt($('.slidesContainer ul').css('left')) - s_width;
$('.slidesContainer ul').animate({
'left': left_indent
},
200,
function () {
//move the first item and put it as last item
$('.slidesContainer li:last').after($('.slidesContainer li:first'));
//set the default item to correct position
$('.slidesContainer ul').css({
'left': l_value
});
});
}
function thumbnailLoop(idx) {
var thumbRun = setTimeout(function () {
thumbnailLoop((idx + 1) % $('.thumbOverlay').length);
}, 3000);
//Remove the class .isActive and add the class to the next .thumbnailOverlay div
$('.thumbOverlay').removeClass('isActive').eq(idx).addClass('isActive');
//Pause the thumbnail rotating on mouseenter. Restart on mouseout.
$('.slidesContainer').hover(
function () {
clearInterval(thumbRun);
},
function () {
thumbRun = setTimeout(function () {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.