我有一个视图,并且在滚动中有一个监听器。问题是滚动函数从dom获取属性以计算何时在页面上加载更多模型。来自模型getted的属性是:scrollHeight,scrollTop,clientHeight。问题是,即使您滚动页面,此属性的值也不会更改。 这看起来很奇怪!我认为向下滚动或向上滚动时滚动顶部必须改变!
var HomePostView = Backbone.View.extend({
tagName: "ul",
// id: "list",
// el:$('.table-view'),
template: Handlebars.compile(template),
initialize: function () {
//console.log(this.collection);
// this.collection.bind("add", this.render, this);
that = this;
document.addEventListener("scroll", this.checkScroll, this);
this.isLoading = false;
this.IntegratedCollection= new Integrated();
this.IntegratedCollection.twitterQuery=11265832;//spostare in load results
this.IntegratedCollection.fetch();
this.listenTo(this.IntegratedCollection,'add',this.render);
console.log((this.el));
},
render:function(){
this.loadResults();
},
loadResults: function (eventName) {
this.isLoading = true;
$(this.el).empty();
_.each(this.IntegratedCollection.models, function (a) {
$(this.el).append(new SingleHomePostView({
model: a
}).render().el);
}, this);
this.isLoading = false;
return this;
},
setParameters: function(){
this.IntegratedCollection.page += 1; // Load next page
this.IntegratedCollection.twitterQuery=11265832;
this.IntegratedCollection.fetch();
},
checkScroll: function () {
console.log("scrollHeight"+that.el.scrollHeight);<--this value doesn't change
console.log("scrollTop"+that.el.scrollTop);<--this value doesn't change
console.log("clientHeight"+that.el.clientHeight);<--this value doesn't change
// console.log(that.el.scrollTop + that.el.clientHeight + triggerPoint);
var triggerPoint = 1; // 100px from the bottom
if(that.el.scrollHeight - that.el.scrollTop === that.el.clientHeight ){console.log("finish spacescroll");};
}
});
答案 0 :(得分:0)
您的问题是一个范围问题。在checkScroll里面,&#34;那个&#34;没有定义。你定义了#34;那个&#34;在初始化。 我并不完全确定你使用&#34; useCapture&#34; addEventListener中的参数,但它将被强制转换为truthy值。可能不是你要找的东西。
document.addEventListener('scroll', this.checkScroll, false);
// ...
checkScroll: function() {
console.log('scrollHeight', this.el.scrollHeight);
//...
}