本文介绍了向上滚动或向下滚动时的 JavaScript 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当手动向上或向下滚动DIV图层的滚动条时,是否可以编写JavaScript来进行操作?
如果是这样,请给我一个提示来实现一个简单的提示框,比如你向上滚动和向下滚动.
解决方案
你可以简单的使用java-script的onscroll
事件.
OnScroll 事件参考:http://www.w3schools.com/jquery/event_scroll.asp
这是一个例子,
<script type="text/javascript">函数 OnScrollDiv (div) {var info = document.getElementById("info");info.innerHTML = "水平:" + div.scrollLeft+ "px<br/>垂直:" + div.scrollTop + "px";}头部><身体><div style="width:200px;height:200px; overflow:auto;"onscroll="OnScrollDiv (this)">请滚动此字段!<div style="height:300px; width:2000px; background-color:#a08080;"></div>请滚动此字段!<div style="height:300px; width:2000px; background-color:#a08080;"></div>请滚动此字段!