Created
February 15, 2012 18:58
-
-
Save alfongj/1838160 to your computer and use it in GitHub Desktop.
Shorter version of Jeffrey Way's jQuery slider done in episode 15 of Learn jQuery in 30 days
This file contains 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
(function($) { | |
var sliderUL = $('div.slider').css('overflow', 'hidden').children('ul'), | |
imgs = sliderUL.find('img'), | |
imgWidth = imgs[0].width, // 600 | |
imgsLen = imgs.length, // 4 | |
current = 0, //0: first | |
$('#slider-nav').show().find('button').on('click', function() { | |
var direction = $(this).data('dir'), | |
move = ( direction === 'next' ) ? 1 : -1; //1 forward, -1 backward | |
current += move; | |
current = (current >= 0) ? (current % imgsLen) : (imgsLen-1); | |
sliderUL.animate({ | |
'margin-left': -current*imgWidth | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment