Js:ResizeObserver 接口监视HTML元素尺寸的变化
发布时间:2022-12-07 12:51:24 355
相关标签: # html# git# github
文档
- https://developer.mozilla.org/zh-CN/docs/Web/API/ResizeObserver
- https://github.com/que-etc/resize-observer-polyfill
文档描述
- ResizeObserver 接口监视 Element 内容盒或边框盒或者 SVGElement 边界尺寸的变化。
使用示例
<style>
#box {
height: 200px;
background-color: #808080;
}
</style>
<div id="box"></div>
<script>
const resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
console.log(entry.contentRect.width);
}
});
resizeObserver.observe(document.querySelector("#box"));
</script>
在线Demo: https://mouday.github.io/front-end-demo/ResizeObserver-demo.html
文章来源: https://blog.51cto.com/mouday/5901198
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报