Define Backtop, reference Scrollto
define ([' jquery ', ' Scrollto '],function ($,scrollto) {
function Backtop (el,opts) {//define Constructor
This.opts=$.extend ({},backtop.defaults,opts);
this. $el =$ (EL);
This.scroll=new Scroll. ScrollTo ({
dest:0,
Speed:this.opts.speed
})
This._checkposition ();
$ (window). On (' scroll ', $.proxy (this._checkposition,this));
if (this.opts.mode== ' move ') {
this. $el. On (' Click ', $.proxy (this._move,this));
}else{
this. $el. On (' Click ', $.proxy (this._go,this));
}
}
Backtop.prototype._move=function () {
This.scroll.move ();
}
Backtop.prototype._go=function () {
This.scroll.go ();
}
Backtop.prototype._checkposition=function () {
var $el =this. $el;
if ($ (window). scrolltop () >this.opts.pos) {
$el. FadeIn ();
}else{
$el. FadeOut ();
}
};
return{
Backtop:backtop;
}
})
JS Object-Oriented Programming 2