gpt4 book ai didi

javascript - 主干滚动事件未触发

转载 作者:行者123 更新时间:2023-11-28 20:10:11 26 4
gpt4 key购买 nike

define([
'jquery',
'underscore',
'backbone',
'collections/jobs',
'text!templates/jobs/list.html'
], function($, _, Backbone, JobCollection, JobListTemplate){
var JobWidget = Backbone.View.extend({
el: '#bbJobList',
initialize: function () {
// isLoading is a useful flag to make sure we don't send off more than
// one request at a time
this.isLoading = false;
this.jobCollection = new JobCollection();
},
render: function () {
this.loadResults();
},
loadResults: function () {
var that = this;
// we are starting a new load of results so set isLoading to true
this.isLoading = true;
// fetch is Backbone.js native function for calling and parsing the collection url
this.jobCollection.fetch({
success: function (jobs) {
// Once the results are returned lets populate our template
$(that.el).append(_.template(JobListTemplate, {jobs: jobs.models, _:_}));
// Now we have finished loading set isLoading back to false
that.isLoading = false;
}
});
},
// This will simply listen for scroll events on the current el
events: {
'scroll': 'checkScroll'
},
checkScroll: function () {
console.log("Scrolling");
var triggerPoint = 50; // 100px from the bottom
if( !this.isLoading && this.el.scrollTop + this.el.clientHeight + triggerPoint > this.el.scrollHeight ) {
this.jobCollection.page += 1; // Load next page
this.loadResults();
}
}
});
return JobWidget;
});

我似乎无法从触发中获取事件。 console.log 甚至不会触发。我还尝试滚动 Windows , el 实际上是一个 div 。对此有何建议?

最佳答案

#bbJobList 元素应该有滚动条 - overflow: auto|scroll css 规则。否则滚动事件不会触发。

关于javascript - 主干滚动事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20021331/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com