简体   繁体   中英

jQuery resize() function causes stack overflow exception

I need to handle div resizing on my web page. The problem is that I have not idea why resize function cause stackoverflow exception. Can you explain me what am I doing wrong?

Here is a jsfiddle example: https://jsfiddle.net/u9q4k4ce/

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script>
    function start() {
        $(document).ready(function () {
            $("#divId").off('resize').on('resize', function () {
            });

            $(window).bind('resize', function () {
                $("#divId").resize();
            });
        });
    }
</script>

</head>
<body onload="start()">
<div id="divId" style="position:absolute;left:0px;right:0px;top:0px;bottom:0px;"></div>
</body>
</html>

In jsfiddle I provided any window resize cause stack overflow. I'm using newest chrome, win 7.

Any help will be appreciated.

Please go through https://api.jquery.com/resize/ . you should pass a callback/handler to your resize().

$( window ).resize(function() {
  $( "#log" ).append( "<div>Handler for .resize() called.</div>" );
});

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