1. 程式人生 > >6.2.27 BOM - scorll系列

6.2.27 BOM - scorll系列

javascrip round onscroll 監聽 ole blue ack div wid

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{padding: 0;margin: 0;}
		</style>
	</head>
	<body style="width: 2000px;height: 2000px;">
		<div style="height: 200px;background-color: red;"></div>
		<div style="height: 200px;background-color: green;"></div>
		<div style="height: 200px;background-color: yellow;"></div>
		<div style="height: 200px;background-color: blue;"></div>
		<div style="height: 200px;background-color: gray;"></div>
		<div id = ‘scroll‘ style="width: 200px;height: 200px;border: 1px solid red;overflow: auto;padding: 10px;margin: 5px 0px 0px 0px;">
			<p>路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城
				路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城
				路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城
				路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城路飛學城
			</p>
			
		</div>
		
		
	</body>
	<script type="text/javascript">
		
		window.onload = function(){
			
			//實施監聽滾動事件
			window.onscroll = function(){
//				console.log(1111)
//				console.log(‘上‘+document.documentElement.scrollTop)
//				console.log(‘左‘+document.documentElement.scrollLeft)
//				console.log(‘寬‘+document.documentElement.scrollWidth)
//				console.log(‘高‘+document.documentElement.scrollHeight)
				
				
			}
			
			var s = document.getElementById(‘scroll‘);
			
			s.onscroll = function(){
//			scrollHeight : 內容的高度+padding  不包含邊框
				console.log(‘上‘+s.scrollTop)
				console.log(‘左‘+s.scrollLeft)
				console.log(‘寬‘+s.scrollWidth)
				console.log(‘高‘+s.scrollHeight)
			}
		}
		
	</script>
</html>

  

6.2.27 BOM - scorll系列