Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

body滚动监听问题 #12

Open
54leibo opened this issue Mar 19, 2020 · 0 comments
Open

body滚动监听问题 #12

54leibo opened this issue Mar 19, 2020 · 0 comments

Comments

@54leibo
Copy link
Owner

54leibo commented Mar 19, 2020

document.body.onscroll = () => console.log('body onscroll') // 正常, 和window.onscroll相互覆盖
document.body.addEventListener('scroll', () => console.log('body addEventListener')) // 无效
document.onscroll = () => console.log('document onscroll') // 正常
document.addEventListener('scroll', () => console.log('document addEventListener')) // 正常
document.documentElement.onscroll = () => console.log('documentElement onscroll') // 无效
document.documentElement.addEventListener('scroll', () => console.log('documentElement addEventListener')) // 无效
window.onscroll = () => console.log('window onscroll') // 正常,和document.body.onscroll 相互覆盖
window.addEventListener('scroll', () => console.log('window addEventListener')) // 正常

说明: 
- 在滚动body时,document对scroll的监听也会被触发
- 这些感觉有点凌乱的API应该是浏览器历史遗留问题,平常的话监听document即可
- 测试环境(userAgenet):Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant