Skip to content

Instantly share code, notes, and snippets.

@jamonholmgren
Created August 8, 2012 00:54
Show Gist options
  • Save jamonholmgren/3291038 to your computer and use it in GitHub Desktop.
Save jamonholmgren/3291038 to your computer and use it in GitHub Desktop.
Slider class example
// Create the Slider class and extend Class.
var Slider = Class.extend(function($el) {
// This is the constructor. First we call the base class's constructor:
Slider.base.call(this);
// Then we do any instantiation
this.target = $el;
this.open = false;
// This is for keeping track of all Slider instances
Slider.all.push(this);
});
// Have to initialize the class var "all"
Slider.all = [];
// These are class methods
Slider.slideUpAll = function(){
Slider.all.forEach(function(s){
s.slideUp();
});
}
// These are instance methods
Slider.prototype.slideUp = function(){
this.target.slideUp("fast");
$("div.black-overlay").removeClass("black-overlay-active");
this.open = false;
};
Slider.prototype.slideDown = function(){
Slider.slideUpAll();
this.target.slideDown("fast");
$("div.black-overlay").addClass("black-overlay-active");
this.open = true;
};
Slider.prototype.slideToggle = function(){
if(this.open) {
this.slideUp();
}else{
this.slideDown();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment