How to detect DIV's dimension changed?

后端 未结 25 2883
抹茶落季
抹茶落季 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:34

    A new standard for this is the Resize Observer api, available in Chrome 64.

    function outputsize() {
     width.value = textbox.offsetWidth
     height.value = textbox.offsetHeight
    }
    outputsize()
    
    new ResizeObserver(outputsize).observe(textbox)
    Width: 0
    Height: 0

    Resize Observer

    Spec: https://wicg.github.io/ResizeObserver

    Polyfills: https://github.com/WICG/ResizeObserver/issues/3

    Firefox Issue: https://bugzil.la/1272409

    Safari Issue: http://wkb.ug/157743

    Current Support: http://caniuse.com/#feat=resizeobserver

提交回复
热议问题