Created
November 10, 2010 21:56
-
-
Save markupboy/671609 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
MH.carousel = function(scope, options) { | |
o = $.extend({}, options, MH.carousel.defaults); | |
var carousel = this, | |
$scope = $(scope), | |
$pages = $(o.pages, scope), | |
$prev = $(o.prev, scope), | |
$next = $(o.next, scope); | |
$current = $pages.eq(0); | |
$current.siblings().css('left', '9999px'); | |
$current.addClass('current'); | |
function advance(direction, next) { | |
var delta = direction*100; | |
next.css('left', delta + '%'); | |
$current.add(next).animate({ | |
left: '-='+delta+'%' | |
}, 'slow'); | |
$current.removeClass('current'); | |
$current = next; | |
$current.addClass('current'); | |
}; | |
$next.bind('click', function() { | |
if(!$(this).hasClass('disabled')) { | |
var next = $current.next(); | |
if(next.length === 0) { | |
next = $pages.eq(0); | |
} | |
advance(1, next); | |
} | |
return false; | |
}); | |
$prev.bind('click', function() { | |
if(!$(this).hasClass('disabled')) { | |
var prev = $current.prev(); | |
if(prev.length === 0) { | |
prev = $pages.eq(-1); | |
} | |
advance(-1, prev); | |
} | |
return false; | |
}); | |
if($pages.length <= 1) { | |
$prev.add($next).addClass('disabled'); | |
} | |
}; | |
MH.carousel.defaults = { | |
pages: 'ul.page', | |
prev: '.prev', | |
next: '.next', | |
speed: 1000, | |
perPage: 18 | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment