<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
height: 2400px;
background-color: grey;
}
</style>
</head>
<body>
<div class="box">
</div>
<script>
function getHtmlScrollHeight(){
var bodyH = 0
var docH = 0
var scrollH = 0
if(document.body){
bodyH = document.body.scrollHeight
}
if(document.documentElement){
docH = document.documentElement.scrollHeight
}
scrollH = (bodyH - docH > 0) ? bodyH : docH;
return scrollH
}
function getWindowHeight(){
var windowH = 0
if(document.compatMode == "CSS1Compat"){
windowH = document.documentElement.clientHeight;
}else{
windowH = document.body.clientHeight;
}
return windowH
}
function getScrollTop(){
var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
if(document.body){
bodyScrollTop = document.body.scrollTop;
}
if(document.documentElement){
documentScrollTop = document.documentElement.scrollTop;
}
scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
return scrollTop;
}
window.onscroll = function(){
if(getWindowHeight() + getScrollTop() === getHtmlScrollHeight()){
p = document.createElement('p')
p.innerText = '新增'
document.body.appendChild(p)
}
}
</script>
</body>
</html>
我没可以用这个来进行一些滚动到底部得操作,比如说加载数据
|