【发布时间】:2016-01-15 00:57:06
【问题描述】:
我在 YouTube 上看过一个关于 Dynamic Content 的视频教程,当用户到达页面底部时,它会自动加载新的 div(类似于 facebook 主页)。它只是继续加载,而不是预期的结果。我不知道如何阻止它。完整代码如下:
<!DOCTYPE html>
<html>
<head>
<script>
function yHandler(){
// Watch video for line by line explanation of the code
// http://www.youtube.com/watch?v=eziREnZPml4
var wrap = document.getElementById('wrap');
var contentHeight = wrap.offsetHeight;
var yOffset = window.pageYOffset;
var y = yOffset + window.innerHeight;
if(y >= contentHeight){
// Ajax call to get more dynamic data goes here
wrap.innerHTML += '<div class="newData"></div>';
}
var status = document.getElementById('status');
status.innerHTML = contentHeight+" | "+y;
}
window.onscroll = yHandler;
</script>
<style>
div#status{position:fixed; font-size:24px;}
div#wrap{width:800px; margin:0px auto;}
div.newData{height:1000px; background:#09F; margin:10px 0px;}
</style>
</head>
<body>
<div id="status">0 | 0</div>
<div id="wrap"><img src="temp9.jpg"></div>
</body>
</html>
要在您的桌面上测试它,请确保您拥有名称为 temp9.jpg
的图像【问题讨论】:
标签: javascript jquery html ajax