Skip to content

Instantly share code, notes, and snippets.

@eerne
Created July 8, 2010 17:46
Show Gist options
  • Save eerne/468355 to your computer and use it in GitHub Desktop.
Save eerne/468355 to your computer and use it in GitHub Desktop.
Slider.implement({
update: function(step){
// same as this.set() but doesn't fire any events
if (!((this.range > 0) ^ (step < this.min))) step = this.min;
if (!((this.range > 0) ^ (step > this.max))) step = this.max;
this.step = Math.round(step);
if (this.previousChange != this.step) this.previousChange = this.step;
this.knob.setStyle(this.property, this.toPosition(this.step));
if (this.previousEnd !== this.step) this.previousEnd = this.step;
return this;
},
resize: function(){
// use resize when the slider bar has a new size
var offset = (this.options.mode == 'vertical') ? 'offsetHeight' : 'offsetWidth';
this.full = this.element.measure(function(){
this.half = this.knob[offset] / 2;
return this.element[offset] - this.knob[offset] + (this.options.offset * 2);
}.bind(this));
this.steps = this.options.steps || this.full;
this.stepSize = Math.abs(this.range) / this.steps;
this.stepWidth = this.stepSize * this.full / Math.abs(this.range);
var limit = {};
this.drag.options.limit[this.axis] = [- this.options.offset, this.full - this.options.offset];
if (this.options.snap){
this.drag.options.grid = Math.ceil(this.stepWidth);
this.drag.options.limit[this.axis][1] = this.full;
}
this.update(this.step);
return this;
}
});
// http://jsfiddle.net/tofu/Dwxht/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment