window监听滚动事件不起作用?
backtop.js文件:
define(['jquery','scrollto'],function($,Scr){
function Backtop(ele,opts){
this.args=$.extend({},Backtop.DEFAULTS,opts);
this.$el=ele;
a=new Scr.Scroll({speed:1800,des:0});
this._check();
this.$el.on('click',$.proxy(this._move,this));
$('window').on('scroll',$.proxy(this._check,this));
}
Backtop.DEFAULTS={
mode:'move',
pos:$(window).height()
}
Backtop.prototype._move=function(){
a.move();
}
Backtop.prototype._check=function(){
if($(window).scrollTop()>this.args.pos){
this.$el.fadeIn();
}else{
this.$el.fadeOut();
}
}
return{
Backtop:Backtop
}
});
回到顶部按钮一直是隐藏的,即使滚动距离大于一屏,但是当滚动距离大于一屏,刷新一下后回到顶部按钮才出现,并且动画可以调用。