且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测HTML5中任何元素的大小调整

更新时间:2023-02-05 23:28:41

嗯,有一个简单的库。虽然没有官方如何倾听所有类型元素的尺寸变化,只有窗口支持它,我们幸运的是,一个polifill非常准确并且支持所有浏览器甚至包含IE6 +。

Well, there is a easy library for that. Although there's nothing official how to listen on dimension changes of all types of elements and only window supports it at the moment we have luckily a polifill for that that works very accurate and supports all browsers even inclusive IE6+.

https:/ /github.com/marcj/css-element-queries

你可以找到一个类 ResizeSensor 。要在元素上设置监听器,您可以这样做:

You can find there a class ResizeSensor. To setup a listener on a element you can just do:

new ResizeSensor($('.myelements'), function() {
    console.log('changed');
});