Skip to content

Instantly share code, notes, and snippets.

@theroux
Created August 6, 2013 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theroux/6165092 to your computer and use it in GitHub Desktop.
Save theroux/6165092 to your computer and use it in GitHub Desktop.
$(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