简体   繁体   English

jQuery resize()函数导致堆栈溢出异常

[英]jQuery resize() function causes stack overflow exception

I need to handle div resizing on my web page. 我需要在网页上处理div大小调整。 The problem is that I have not idea why resize function cause stackoverflow exception. 问题是我不知道为什么调整大小功能会导致stackoverflow异常。 Can you explain me what am I doing wrong? 你能解释一下我在做什么错吗?

Here is a jsfiddle example: https://jsfiddle.net/u9q4k4ce/ 这是一个jsfiddle示例: 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. 在jsfiddle中,我提供了任何窗口大小调整都会导致堆栈溢出的问题。 I'm using newest chrome, win 7. 我正在使用最新的Chrome,请赢得7。

Any help will be appreciated. 任何帮助将不胜感激。

Please go through https://api.jquery.com/resize/ . 请通过https://api.jquery.com/resize/进行 you should pass a callback/handler to your resize(). 您应该将回调/处理程序传递给您的resize()。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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