简体   繁体   中英

Getting a div scroll position 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?

The scrollTop property tells you the vertical scroll position:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM