gpt4 book ai didi

javascript - window.height 和 document.height 返回相同的值

转载 作者:行者123 更新时间:2023-11-28 08:55:11 25 4
gpt4 key购买 nike

在下面的代码中,我尝试实现无限滚动。我遇到的问题是“document.height”和“window.height”返回相同的值。有人可以帮我解决我哪里出错了吗?

<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
$(window).scroll(function(){
if($(window).scrollTop() == $(document).height() - $(window).height()){
$('div#loadmoreajaxloader').show();
$.ajax({
url: "loadmore.php",
success: function(html){
if(html){
$("#postswrapper").append(html);
$('div#loadmoreajaxloader').hide();
console.log($(document).height());
console.log($(window).height());
}else{
$('div#loadmoreajaxloader').html('<center>No more posts to show.</center>');
}
}
});
}
});
</script>

<style>
body{ margin:0px; }

#wrapper{
width:600px;
margin:auto;
}
.spacer{
clear:both;
height:5px;
}
.txtarea{
font-size:18px;
height:50px;
width:100%;
}
#postswrapper{
border-bottom:1px dotted #555555;
}
.item{
border-top:1px dotted #555555;
padding:10px 5px;
font-size: 16px;
}
.item:hover{
background:#EFEFEF;
}
#newpostlink{
display:block;text-align:center;border:2px solid #414141;background:#7D7D7D;color:#fff; margin: 0 0 10px;padding:5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px;font-size:20px;text-decoration:none;
}
</style>


</head>

<body>
<div id="wrapper">
<div id="postswrapper">

<p style="font-size:28px">Infinite Scroll Demo 2</p>

<div class="item">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>

<div class="item">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>

<div class="item">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>

<div class="item">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>

<div id="loadmoreajaxloader" style="display:none;"><center><img src="ajax-loader.gif" /></center></div>

</div>

<div id="footer" style="display:inline-block;width:100%;padding:10px;background-color:#FFFFFF">


</div>

</body>



</html>

最佳答案

也许可以尝试一下...

if ($(window).scrollTop() <= $(document).height() - $(window).height()) {

关于javascript - window.height 和 document.height 返回相同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18607756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com