JS judges that the box scrolls to the bottom

Understand three concepts

a.scrollTop ----> the distance above the a box is rolled

a.scrollHeight ----> the true height of a box, including hidden

a.offsetHeight —> the visual height of a box,Insert picture description here

Then, when the rolled height is equal to the real height-the visible height, that is, when the hidden height you can't see in the picture above is equal to the height of the box being rolled, it reaches the bottom.
So if (a.scrollTop === a.scrollHeight-a.offsetHeight ){ console.log('to the bottom')}

Guess you like

Origin blog.csdn.net/lin_fightin/article/details/111991139