Created
October 11, 2011 03:22
-
-
Save rmdort/1277192 to your computer and use it in GitHub Desktop.
Simple Carousel with prev, next and pager
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
var carousel = { | |
init: function(){ | |
this.carousel = jQuery('#Testimonials'); | |
this.prev = $('#PagePrev'); | |
this.next = $('#PageNext'); | |
this.pager = $('#Pager'); | |
this.appendpager(); | |
this.prev.bind('click',{direction:'prev', ele : this}, this.slidenav); | |
this.next.bind('click',{direction:'next', ele : this}, this.slidenav); | |
this.pager.delegate('li','click',{ele : this}, this.slidenav); | |
}, | |
appendpager : function(){ | |
var cc = this; | |
this.carousel.find('ul:eq(0)').find('li').each(function(i){ | |
cc.pager.find('ul').append('<li><a href="#">'+i+'</a>'); | |
}); | |
cc.pager.find('li:first').addClass("active"); | |
} | |
, slidenav : function(e){ | |
var $this = e.data.ele, | |
$items = $this.carousel.find('ul:eq(0)').find('li'), | |
$item = $(this); | |
if(e.data.direction == "next"){ | |
$item = $this.pager.find('.active').next().length ? $this.pager.find('.active').next() : $this.pager.find('li:first'); | |
} | |
if(e.data.direction == "prev"){ | |
$item = $this.pager.find('.active').prev().length ? $this.pager.find('.active').prev() : $this.pager.find('li:last'); | |
} | |
$this.carousel.find('ul').eq(0).animate({ | |
left: -($item.prevAll().length * 900) | |
},400,'easeOutQuart'); | |
$item.siblings().removeClass("active").end().addClass("active"); | |
e.preventDefault(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment