$(function() { //Get the initial carousel width to set the negative positioning of the first slide headline var $initWidth = "-" + parseInt( $(".carouselwrapper").width() ) + "px"; var total_slides = $("#slides .slide").length; var psuedo_counter = 0; //Animate the initial headline on load $(".carouselwrapper .slide").eq(0).children(".headline").css('left',$initWidth).animate({ left: '0px' }, 1000, 'swing'); //Set the default state for the rest of the slides $(".carouselwrapper .slide").not(":eq(0)").children(".headline").css('left', $initWidth); $('#slides').slides({ container: 'carouselwrapper', play: 5000, //Comment this line out to run manually. fadeSpeed: 600, generateNextPrev: false, //Change this to true to step through slides manually generatePagination: false, crossfade: true, effect: 'fade', animationStart: function(current,prev,next) { psuedo_counter = psuedo_counter + 1; psuedo_counter = total_slides === psuedo_counter ? 0 : psuedo_counter; var $currentWidth = "-" + parseInt( $(".carouselwrapper").width() ) + "px"; $(".carouselwrapper .slide").eq(psuedo_counter).children(".headline").animate({ left: '0px' }, 1000, 'swing', function(){ $(".carouselwrapper .slide").not(":eq("+psuedo_counter+")").children(".headline").css('left', $currentWidth); }); //console.log("The prev slide is " + prev); //console.log("The current slide is " + current); //console.log("The counter reads " + psuedo_counter); } }); });