简体   繁体   中英

Resetting element CSS attributes on container resize event (onresize)

I have a function in the onresize event of a wrapper div to resize an element. That function isn't called. Is the onresize event not available for divs?

Here is the HTML.

<div id="matting" onresize="resize_page();"> <!-- Begin page matting div -->

  <div id="page"> <!-- Begin page div -->

  </div> <!-- End page div -->

</div> <!-- End page matting div -->
<script type="text/javascript">
    function resize_page() {
        alert ('resize_page');
        $("#page").css('height','120%');
    }
</script>

The onresize event occurs when a window or frame is resized.

So, it seems it isn't supported for div

http://www.w3schools.com/jsref/event_onresize.asp

You can use jquery plugin http://benalman.com/projects/jquery-resize-plugin/ An internal polling loop is started which periodically checks for element size changes and triggers the event when appropriate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM