Skip to content
fe-handbook
Search
K
Main Navigation
fundamentals
HTML
CSS
JavaScript
TypeScript
Browser
HTTP
Network
build-tools
Package-manager
npm
yarn
pnpm
Bundler
Vite
Webpack
Compiler
Babel
swc
framework
Vue
React
advance
Nodejs
SSR
Test
Event Tracking
Low Code
Micro-frontends
PWA
WebGL
i18n
other
Useful Libraries
Code Style
Matrix
Awesome
Appearance
Menu
Return to top
On this page
判断元素是否在视窗内
Element.getBoundingClientRect()
监听滚动事件,获取元素坐标,与视口尺寸比较
频繁触发,性能差
IntersectionObserver API
注册监听元素交叉监听事件
利用浏览器空闲时段触发,性能好
Reference
https://juejin.cn/post/6844903788914933774
https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API