1

当下面的代码运行时浏览器挂起。这是我的代码

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/CenterDiv.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#Main').center();
        $('#Main').bind('scroll', function () {
            if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
                //var new_div = '<div class="new_block"></div>';
                //$('.main_content').append(new_div.load('/path/to/script.php'));
                alert("end");
            }
        });

    });
</script>
<style type="text/css">
.centered
{
    height:640px;
    width:700px;
    border-color:Black;
    border-width:2px;
    border-style:solid;
    overflow:scroll
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="Main" class="centered">
    <img src="images/img1.jpg" />
</div>
</form>
</body>
</html>

实际上导致浏览器挂起的代码是

$('#Main').bind('scroll', function () {
            if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
                //var new_div = '<div class="new_block"></div>';
                //$('.main_content').append(new_div.load('/path/to/script.php'));
                alert("end");
            }
        });

通过上面的代码,我试图检测滚动条是否拖到 div 的末尾。为什么我会出错....请指教。谢谢

4

0 回答 0