Created
August 6, 2013 14:40
-
-
Save theroux/6165092 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(window).load(function() { | |
var $fadedElems = $('body').find('.faded'); | |
$fadedElems.removeClass('faded'); | |
}); | |
$(function() { | |
var $container = $('.img-container'), | |
$childElement = $('.img-container img'), | |
imgArray = [], | |
currentImg = 0; | |
$(window).load(function() { | |
$childElement.each(function() { | |
var leftOffset = parseInt($(this).offset().left); | |
console.log(leftOffset); | |
imgArray.push(leftOffset); | |
}); | |
$(document).keydown(function(e) { | |
if ((e.keyCode || e.which) == 37) { // left arrow | |
if (currentImg === 0 ) { | |
//on first slide, can't go left | |
$container.animate({scrollLeft: '0px'}); | |
return; | |
} else { | |
e.preventDefault; | |
currentImg--; | |
scrollFunction(); | |
} | |
} | |
if ((e.keyCode || e.which) == 39) { // right arrow | |
if (currentImg === (imgArray.length -1)) { | |
//on last slide, can't go right | |
e.preventDefault; | |
return; | |
} else { | |
//not on last slide | |
console.log('right!' + (imgArray[currentImg]) ); | |
e.preventDefault; | |
currentImg++; | |
scrollFunction(); | |
} | |
} | |
}); | |
var scrollFunction = function() { | |
$container.stop().animate({scrollLeft: (imgArray[currentImg]) + 'px'}); | |
}; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment