How to detect DIV's dimension changed?

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

    You have to bind the resize event on the window object, not on a generic html element.

    You could then use this:

    $(window).resize(function() {
        ...
    });
    

    and within the callback function you can check the new width of your div calling

    $('.a-selector').width();
    

    So, the answer to your question is no, you can't bind the resize event to a div.

提交回复
热议问题