我正在尝试在uswr在div中滚动50px时提醒消息,但它不起作用:
function handleScroll() {
console.log('scrolling... ', this.offsetTop);
if(this.offsetTop > 50) alert('scrolled more than 50px!');
}
document.getElementById('a').addEventListener('scroll', handleScroll);
这是怎么回事? codepen demo
答案 0 :(得分:1)
function handleScroll() {
alert('scrolling... '+ this.scrollTop);
if(this.scrollTop > 50) alert('scrolled more than 50px!');
}
document.getElementById('a').addEventListener('scroll', handleScroll);