jQuery(document).ready(function($){ function initTimeline(){ $('.cd-timeline-content-inner').matchHeight({ byRow: false }); var timer = 0; var container = $('.cd-container'); var navButtons = $('.nav-buttons .back, .nav-buttons .forward'); var entries = container.find('.cd-timeline-block'); if(container.size() > 0){ function setupHorizontalTimeline(){ var timerStarted = false; var scrollDistance = 10; var counter = 0; navButtons.hover(function(){ var button = $(this); timerStarted = true; function startTimer(){ timer = setTimeout(function(){ if(timerStarted){ move(button.hasClass('forward')); }else{ stop(); } }, 25); } function move(moveForward){ var scrollDirection = ""; if(moveForward){ scrollDirection += "+="; }else{ scrollDirection += "-="; } container.scrollTo(scrollDirection + scrollDistance + "px"); if(timerStarted){ startTimer(); } } function stop() { clearTimeout(timer); timer = 0; } startTimer(); }, function(){ timerStarted = false; clearTimeout(timer); timer = 0; }); navButtons.click(function(event){ var button = $(this); var scrollDirection = ""; if(button.hasClass('forward')){ scrollDirection += "+="; }else{ scrollDirection += "-="; } container.scrollTo(scrollDirection + (scrollDistance * 50) + "px"); event.preventDefault(); return false; }); // using the event helper container.mousewheel(function(event) { var scrollChange = event.deltaY * 50; if(event.deltaY > 0){ container.scrollTo("-=" + scrollChange + "px"); }else{ container.scrollTo("+=" + (scrollChange * -1) + "px"); $(window).scrollTo(container); } if(container.scrollLeft() != 0){ event.preventDefault(); } }); entries.each(function(){ var entry = $(this); entry.css({ position:"absolute", width: "600px", left: (600/1.25 * counter) + 100 }); counter += 1; }); } function removeHorizontalTimeline(){ entries.css({ position: "relative", width: "inherit", left: "inherit" }); container.unbind("mousewheel"); navButtons.unbind("hover"); $('.cd-timeline-content-inner').unbind('matchHeight'); } $(window).resize(function(){ if($(window).width() > 991){ setupHorizontalTimeline(); } else { removeHorizontalTimeline(); } }); $(window).resize(); } } initTimeline(); });