關于backtop.js文件判斷瀏覽器屏幕滾動條代碼
老師可以發下源碼嗎?照著打的還是會出現問題,當滾動一屏時返回頂部的按鈕顯示不出來,只有刷新可以顯示,哪里錯了呢?
define(['jquery','scrollto'],function($,scrollto){
function?BackTop(el,opts){
????????this.opts=$.extend({},BackTop.DEFAULTS,opts);
????????this.$el=$(el);
????????this.scroll=new?scrollto.ScrollTo({
???????? dest:0,
???????? speed:this.opts.speed
????????});
????????this._checkPosition();
????????if(this.opts.mode?=='move'){
???????????this.$el.on('click',$.proxy(this._move,this));
????????}else{
???????????this.$el.on('click',$.proxy(this._go,this));
????????}
????????
????????$(window).on('scroll',$.proxy(this._checkPosition.this));
}
BackTop.DEFAULTS={
mode:'move',
pos:$(window).height(),
speed:800
}
????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){
???????? ?//alert(this.opts.pos)
???????? //?console.log($(window).scrollTop)
???????????this.$el.fadeIn()
????????}else{
???????????this.$el.fadeOut();
????????}
????};
?????$.fn.extend({
????? backtop:function(opts){
????? return?this.each(function(){
????? new?BackTop(this,opts)
????? })
?????
????? }
?????})
????return?{
???? BackTop:BackTop
????};
})