vahid najafi vahid najafi - 3 years ago 121
AngularJS Question

javascript get scroll of child div

I have a structure something like this:

<div>

<div id="scrollID" style="height:100px;">
content here
</div>

</div>

<script>
document.getElementById("myDIV").addEventListener("touchstart", myFunction);
function myFunction() {
// want to get my position
}
</script>


I want to get the distance from top, when user start scrolling (actually touching in mobile). My final purose is implementing pull to refresh for child
div
.

Any idea?

Answer Source

Try the following.

<div>

    <div id="scrollID" style="height:100px;" onscroll="myFunction();">
         content here
    </div>

</div>

<script>
document.getElementById("myDIV").addEventListener("touchstart", myFunction);
function myFunction() {
    document.getElementById("scrollID").scrollTop;
    // want to get my position
}
</script>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download