最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Getting a div scroll position using javascript. - Stack Overflow

programmeradmin5浏览0评论

I have one button in a div tag. That div tag also has a vertical scroll bar.

If I scroll that bar and click on the button which is inside that div, it should return the scroll position as an alert message.

How to do that using JavaScript?

I have one button in a div tag. That div tag also has a vertical scroll bar.

If I scroll that bar and click on the button which is inside that div, it should return the scroll position as an alert message.

How to do that using JavaScript?

Share Improve this question edited Sep 6, 2011 at 9:27 Py. 3,6091 gold badge36 silver badges55 bronze badges asked Sep 6, 2011 at 7:40 SwaroopSwaroop 211 gold badge3 silver badges7 bronze badges 2
  • 1 You could do this pretty easily with jquery. Is that an option? – Matt Commented Sep 6, 2011 at 7:41
  • Possible duplicate of retrieve Scrollbar position with javascript – Félix Adriyel Gagnon-Grenier Commented Dec 31, 2015 at 11:21
Add a ment  | 

1 Answer 1

Reset to default 2

The scrollTop property tells you the vertical scroll position:

document.getElementById("yourButton").onclick = function() {
   alert(document.getElementById("yourDiv").scrollTop); 
}
发布评论

评论列表(0)

  1. 暂无评论