是否可以编写 JavaScript 来在手动向上或向下滚动 DIV 层的滚动条时执行操作?
如果是这样,请给我一个提示,以实现一个简单的警报框,表示您向上滚动并向下滚动。
您可以简单地使用onscroll
java脚本的事件。
OnScroll 事件参考 : http://www.w3schools.com/jquery/event_scroll.asp http://www.w3schools.com/jquery/event_scroll.asp
这是一个例子,
<head>
<script type="text/javascript">
function OnScrollDiv (div) {
var info = document.getElementById ("info");
info.innerHTML = "Horizontal: " + div.scrollLeft
+ "px<br/>Vertical: " + div.scrollTop + "px";
}
</script>
</head>
<body>
<div style="width:200px;height:200px; overflow:auto;" onscroll="OnScrollDiv (this)">
Please scroll this field!
<div style="height:300px; width:2000px; background-color:#a08080;"></div>
Please scroll this field!
<div style="height:300px; width:2000px; background-color:#a08080;"></div>
Please scroll this field!
</div>
<br /><br />
Current scroll amounts:
<div id="info"></div>
</body>
工作副本在这里:http://jsbin.com/iledat/2/edit http://jsbin.com/iledat/2/edit
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)