admin管理员组文章数量:1312662
Is it possible to write a JavaScript to make an action when a DIV Layer's scroll bar is manually scrolled up or scrolled down?
If so please give me a hint to implement a simple such as alert box saying you scrolled up and you scrolled down.
Is it possible to write a JavaScript to make an action when a DIV Layer's scroll bar is manually scrolled up or scrolled down?
If so please give me a hint to implement a simple such as alert box saying you scrolled up and you scrolled down.
Share Improve this question edited Feb 23, 2017 at 12:08 Pooja Kedar 4372 gold badges10 silver badges23 bronze badges asked Dec 9, 2011 at 13:11 Mad coder.Mad coder. 2,1759 gold badges38 silver badges53 bronze badges 1- This should help you: adomas/javascript-mouse-wheel – Felix Kling Commented Dec 9, 2011 at 13:20
2 Answers
Reset to default 8You can simple use onscroll
event of java-script.
OnScroll Event Reference : http://www.w3schools./jquery/event_scroll.asp
Here is example,
<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>
Working copy here : http://jsbin./iledat/2/edit
Try jquery scroll event.
$('div').scroll(function(){alert('scrolled!')})
本文标签: JavaScript event on scroll up or scroll downStack Overflow
版权声明:本文标题:JavaScript event on scroll up or scroll down - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741912597a2404532.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论