<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
body {
margin: 0;
}
#box {
width: 100px;
height: 100px;
margin: 50px;
background-color: red;
border: 10px solid yellow;
padding: 15px;
overflow: auto;
/*overflow: hidden;*/
}
</style>
</head>
<body>
<div id="box">涉及一些优秀攻城狮的优秀博客、社区,实用的手册、工具</div>
<script>
var box = document.getElementById('box');
// // scrollLeft scrollTop分别对应的是滚动出去的内容的大小 包括border 非滚动条运动的距离
// console.log(box.scrollLeft); // 0
// console.log(box.scrollTop); // 0
// // 内容的大小,包含padding和未显示的内容,不包含滚动条
// console.log(box.scrollWidth); // 113
// console.log(box.scrollHeight); // 156
// // 元素的大小+padding 不包含滚动条 可视区域
// console.log(box.clientWidth); // 113
// console.log(box.clientHeight); // 130
// 拖动滚动条时触发
box.onscroll = function () {
console.log('box.scrollLeft: ' + box.scrollLeft); // 0
console.log('box.scrollTop: ' + box.scrollTop);
console.log('box.scrollWidth: ' + box.scrollWidth); // 113
console.log('box.scrollHeight: ' + box.scrollHeight); // 156
}
</script>
</body>
</html>