How to detect DIV's dimension changed?

后端 未结 25 2761
抹茶落季
抹茶落季 2020-11-22 06:14

I\'ve the following sample html, there is a DIV which has 100% width. It contains some elements. While performing windows re-sizing, the inner elements may be re-positioned,

25条回答
  •  爱一瞬间的悲伤
    2020-11-22 06:53

    Only Window.onResize exists in the specification, but you can always utilize IFrame to generate new Window object inside your DIV.

    Please check this answer. There is a new little jquery plugin, that is portable and easy to use. You can always check the source code to see how it's done.

    
    
    
    // (2) use the detectResizing plugin to monitor changes to the element's size:
    $monitoredElement.detectResizing({ onResize: monitoredElement_onResize });
    
    // (3) write a function to react on changes:
    function monitoredElement_onResize() {    
        // logic here...
    }
    

提交回复
热议问题