Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to listen to the bottom of the scroll bar in vue

Shulou Source: shulou.com Published: 2022-05-31 12:06:15 09月10日 Update

This article introduces the knowledge of "how to listen to the bottom of the scroll bar in vue". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. How to use pure js to determine whether the scroll bar is at the bottom?

Learn about a few key words first:

(1) position of scroll bar to the top: scrollTop

(2) visible area of the current window: windowHeight

(3) Total height of scroll bar content: scrollHeight

The functions that trigger snooping are:

_ window.onscroll = function () {.}

The equation at the bottom: scrollTop+windowHeight=scrollHeight

2. Main function code

Created () {_ window.onscroll = function () {/ / variable scrollTop is the distance from the top of the scroll bar var scrollTop = document.documentElement.scrollTop | | document.body.scrollTop; / / variable windowHeight is the height of the visible area var windowHeight = document.documentElement.clientHeight | | document.body.clientHeight; / / variable scrollHeight is the total height of the scroll bar var scrollHeight = document.documentElement.scrollHeight | | document.body.scrollHeight / / condition if to the bottom of the scroll bar (scrollTop+windowHeight==scrollHeight) {/ / write the function console.log for loading data in the background ("height from the top" + scrollTop+ "visual area height" + windowHeight+ "total scroll bar height" + scrollHeight);}} "how to listen to the bottom of the scroll bar in vue". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Height content monitoring functions variables view more knowledge top utility learning next code location key keywords background dilemma actual situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Tech Info Redmi vpn Shulou Information