开发者

Getting a div scroll position using javascript.

I have one button in a div tag. T开发者_Go百科hat 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?


The scrollTop property tells you the vertical scroll position:

document.getElementById("yourButton").onclick = function() {
   alert(document.getElementById("yourDiv").scrollTop); 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜