Learn how to use jQuery at the Blog

HALO Creative Agency « visit

  • Added 11 months ago
  • 47 Lines of Code shown
  • 1 Links of Interest
http://haloagency.net
This is my Source Code and I don't want to show it here
View Source Code only (as overlay)
// That code snippet belongs to HALO Creative Agency - http://haloagency.net

$(document).ready(function() {
    var timeOut     = 16000;
    var current     = null;
    var timeOutFn   = null;
    var items       = $(".featuredImg");

    var startSlider = function() {
        if(items.length > 0) {
            timeOutFn = setTimeout(makeSlider, timeOut);
        } else {
            console.log("Poof..");
        }
    }

    var makeSlider = function() {
        if(current != null) {
            var currNo = jQuery.inArray(current, items) + 1;
            
            if(currNo == items.length) {
                var currNo = 0;
                var duration = 1800;
            } else {
                var duration = 900;
            }
            var newMargin   = ($(current).width() * currNo) + (4 * currNo);
            $("#featured a").animate({ 
                left: -newMargin + "px"
            }, { 
                queue:true, 
                duration: duration
            });
            current = items[currNo];
            startSlider();
        } else {
            var newMargin   = $(items[0]).width() * 1;
            $("#featured a").animate({
                left: -newMargin + "px"
            }, { 
                queue:true,
                duration: 900
            });
            current = items[1];
            startSlider();
        }
    }
    startSlider();
});