How to detect CSS3 resize events

前端 未结 6 1294
庸人自扰
庸人自扰 2020-12-01 15:42

The CSS3 resize property can be assigned to arbitrary elements. I\'m looking for a way to detect such a resize on, say, divs (I don\'t mind it only working in Firefox at the

6条回答
  •  孤街浪徒
    2020-12-01 16:35

    You can use the ResizeSensor class of the css-element-queries polyfill from

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

    It allows you to call a javascript function on size changes for all types of elements, not only for window. It sets up a real sensor, not a javascript setTimeout poll.

    Use it like this:

    new ResizeSensor($('#myelement'), function() {
        console.log("myelement's size has changed");
    });
    

    Supported browsers are: all incl. IE6+.

提交回复
热议问题