问答详情
源自:5-4 封闭成工具条模块

为什么BackTop 提示未定义呢 Cannot read property 'BackTop' of undefined

http://img.mukewang.com/575e5a8d0001318b10140383.jpg

define(['jquery','scrollto'],function($,scrollto){

function BackTop(el,opts){

this.opts = $.extend({},BackTop.DEFAULTS,opts);

this.$el = $(el);

this.scrollto = 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.scrollto.move();

};

BackTop.prototype._go = function(){

this.scrollto.go();

};

BackTop.prototype._checkPosition = function(){

var el = this.$el;

if($(window).scrollTop() > this.opts.pos){

el.fadeIn();

}else{

el.fadeOut();

}

};


  // 将返回功能模块封装在jq上

$.fn.extend({

backtop: function(opts){

return this.each(function(){

new BackTop(this,opts)

})

}

});

return{

BackTop:BackTop

}

})



提问者:tlx6550 2016-06-13 15:03

个回答

  • 猿小二
    2016-06-15 16:54:03

    this.scrollto = new scrollto.ScrollTo()  改为 this.scroll = new scrollto.ScrollTo()

    把下面的相应的this.scrollto都改成this.scroll

    因为引入的模块儿叫scrollto  所以这边再用scrollto可能是起冲突了