Skip to content

Instantly share code, notes, and snippets.

@markupboy
Created November 15, 2011 21:32
Show Gist options
  • Select an option

  • Save markupboy/1368425 to your computer and use it in GitHub Desktop.

Select an option

Save markupboy/1368425 to your computer and use it in GitHub Desktop.
window.PA = window.PA || {};
PA.homeslider = {
init: function() {
this.setDom('#panels');
this.setOptions();
this.setActive(0);
this.bindNav();
this.startCycle();
this.bindGestures();
},
bindGestures: function() {
this.scope.hover($.proxy(this.stopCycle, this), $.proxy(this.startCycle, this));
},
bindNav: function() {
this.nav.find('a').each(this.setupNavItem).
bind('click', $.proxy(this.navigate, this));
},
cycle: function() {
this.next();
this.startCycle();
},
goTo: function(index) {
if(index !== this.active) {
var endPoint = -1 * this.panelSize * index;
this.setActive(index);
this.track.animate({
left: endPoint
}, this.speed, 'swing');
}
},
navigate: function(e) {
e.preventDefault();
this.goTo($(e.target).data('panel-index'));
},
next: function() {
var next = this.active + 1 > this.panelCount - 1 ? 0 : this.active + 1;
this.goTo(next);
},
setActive: function(index) {
this.active = index;
this.activeObj = this.panels.eq(index);
this.nav.find('a[href=#'+this.activeObj.attr('id')+']').parent().addClass('active').
siblings().removeClass('active');
},
setDom: function(scope) {
this.scope = $(scope);
this.track = this.scope.find('.panels');
this.panels = this.track.children('li');
this.nav = this.scope.find('.panel-nav');
},
setOptions: function() {
this.speed = 1000;
this.delay = 5000;
this.panelSize = 1920;
this.panelCount = this.panels.length;
},
setupNavItem: function() {
var $this = $(this),
panelIndex = $($this.attr('href')).prevAll().length;
$(this).data('panel-index', panelIndex || "0");
},
startCycle: function() {
this.timeout = setTimeout($.proxy(this.cycle, this), this.delay);
},
stopCycle: function() {
this.timeout && clearTimeout(this.timeout);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment