DOM中的scroll属性

<!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>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值