在 div 滚动时动态检查 div 的 offsetTop
Check offsetTop of div dynamically on div scroll
我正在尝试在 div 中 uswr 滚动 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
function handleScroll() {
alert('scrolling... '+ this.scrollTop);
if(this.scrollTop > 50) alert('scrolled more than 50px!');
}
document.getElementById('a').addEventListener('scroll', handleScroll);
我正在尝试在 div 中 uswr 滚动 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
function handleScroll() {
alert('scrolling... '+ this.scrollTop);
if(this.scrollTop > 50) alert('scrolled more than 50px!');
}
document.getElementById('a').addEventListener('scroll', handleScroll);