代码如下
几个console.log都没触发
还有个问题请问大佬,请问window.onscroll=function(e){} 这个的解绑是让 window.onscroll 直接等于空就行吗
getMore(Boolean){
var self = this;
if(Boolean){
console.log(document.getElementById('SimpleList'))
//以下
document.getElementById('SimpleList').onscroll= function (e){
console.log('111')
var htmlHeight =document.body.scrollHeight || document.documentElement.scrollHeight;
var clientHeight =window.innerHeight || document.documentElement.clientHeight;
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
let validH = htmlHeight - clientHeight;
let result = ((scrollTop / validH) * 100).toFixed(2);
console.log(result)
if (self.nullData) {
return;
} else if (result == 100) {
self.isUpData = true;
self.page += 1;
self.getList();
}
};
1、应该是在触发前绑定事件,而不是触发后,否则会错过
2、onscroll等同于addEventListener,赋值为空函数还是会执行。要移除事件绑定,需要执行的是removeEventListener