How to detect resize of any element in HTML5

后端 未结 4 780
时光取名叫无心
时光取名叫无心 2021-02-13 12:05

What should the best practices to listen on element resize event?

I want to re-position an element (jQuery dialog in my case), once it\'s size changed. But I am now more

4条回答
  •  醉话见心
    2021-02-13 12:47

    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

    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');
    });
    

提交回复
热议问题