JavaScript 如何手動觸發窗口滾動事件

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		.box{height:2000px;}
	</style>
</head>
<body>
	<div class="box"></div>
	<script>
		window.οnscrοll=function(){alert(1)}
		var evt = window.document.createEvent('UIEvents'); 
	    evt.initUIEvent('scroll', true, false, window, 0); 
	   window.dispatchEvent(evt);
	</script>
</body>
</html>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章