How to detect resize of any element in HTML5

后端 未结 4 777
时光取名叫无心
时光取名叫无心 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:45

    Yes there is not simple solution, that's not good.

    I've found something very useful for this.: cross browser event based element resize

    It's tricky, appending some needed html to the element that have to be listened and detects scrolling event.

    Some html example from that page:

    Also Some JS:

    var myElement = document.getElementById('my_element'),
        myResizeFn = function(){
            /* do something on resize */
        };
    addResizeListener(myElement, myResizeFn);
    removeResizeListener(myElement, myResizeFn);
    

    But it works for elements those are able to have children, not for self-closing tags.

    You can see the demo http://jsfiddle.net/3QcnQ/67/

提交回复
热议问题