Skip to content

Instantly share code, notes, and snippets.

@pavlakis
Created February 3, 2013 19:12
Show Gist options
  • Save pavlakis/4703225 to your computer and use it in GitHub Desktop.
Save pavlakis/4703225 to your computer and use it in GitHub Desktop.
Model for the slider example app
// slides model
define([], function () {
return function (containerId) {
this.containerId = containerId,
this.slideWidth = 400,
this.slidePosition = 0,
this.totalSlidesNo = 0,
this.addSlide = function(slide) {
this.totalSlidesNo++;
$('#' + containerId).append(slide.getHtml());
},
this.setSlideWidth = function(width) {
this.slideWidth = width;
},
this.setTotalSlidesNo = function (number) {
this.totalSlidesNo = number;
},
this.moveLeft = function() {
if (Math.abs(this.slidePosition) >= Math.abs( (this.slideWidth * this.totalSlidesNo) - this.slideWidth ) ) {
return false;
}
this.slidePosition -= this.slideWidth;
$('#' + containerId).animate({left: "-=" +this.slideWidth +"px"}, 700);
},
this.moveRight = function() {
if (this.slidePosition == 0) {
return false;
}
this.slidePosition += this.slideWidth;
$('#' + containerId).animate({left: "+=" +this.slideWidth +"px"}, 700);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment