


Detailed explanation of js to determine whether the content area is scrolled to the bottom
To determine whether the content is scrolled to the end, you need to know the real height of the content area (that is, the scroll area), the position of the scroll bar from the top, and the visible height of the content area. This article mainly shares a js native judgment of whether the content area has scrolled to the bottom. The example code has a good reference value. I hope it can help everyone.
corresponds to the following three APIs respectively.
element.scrollHeight Gets the content height of the element,,, [Read-only attribute]
element.scrollTop can get or set the offset value of the element. It is often used to calculate the position of the scroll bar. If the container of an element does not generate a vertical scroll bar, its scrollTop value defaults to 0.
element.clientHeight Reads the visible height of the element [read-only attribute]
Directly below Quoting a classic formula on MDN
Determine whether the element scrolls to the end
If the element scrolls to the end, the following equation returns true, otherwise it returns false.
element.scrollHeight - element.scrollTop === element.clientHeight
Case-User Agreement
Only after the user has finished reading the agreement can they click to agree, which means that after the scroll bar reaches the bottom, it means Finish reading
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>tab</title> <style> textarea{height: 200px;width: 300px} </style> </head> <body> <p> <textarea> 用户咨询条款 一、咨询系统提供的服务 1、本网站咨询系统(以下简称“本系统”)为用户提供参与各种咨询项目(以下简称“项目”)的机会。用户在包之网上注册成为会员,并可申请某一专家会员通过包之网平台及电话等方式为其提供咨询服务。 2、您应按照您想要咨询的专家其所对应的专家收费金额,根据您希望互动/通话时间的长短,预先存入咨询费用,方可进行预约、咨询。咨询完成后,剩余的款项将在15个工作日内直接退还给您。您应提供详细的收款信息,否则本网站不承担任何责任。提请您注意,若预存金额过低,可能导致咨询中断。咨询费用根据本网站标准的专家收费金额及实际通话时间进行计算。您同意因银行处理本网站对您的每一笔付款所产生的全部费用将由您自行承担。 3、如果您对专家的工作内容或提供咨询服务质量等有异议,则在此等争议完全解决之前,本网站将扣留应付给您的款项。 4、如果您需要发票,应直接向提供咨询的专家要求,本网站不提供任何发票。 5、专家收费详见本网站不时发布的专家收费金额。专家收费金额及其修改均为本条款不可分割的组成部分,请您申请前仔细查看。 6、本网站根据实际情况尽可能根据您的要求、申请与专家进行匹配, 但专家有权不予提供服务。 </textarea> </p> <p> <input type="checkbox" value="1" disabled="disabled"> 同意 </p> <script> //获取checkbox元素 var checkbox=document.querySelector('input[type=checkbox]'); document.querySelector('textarea').addEventListener('scroll',function () { //读取内容区域的真实高度(滚动条高) // console.log(this.scrollHeight); //读取滚动条的位置 // console.log(this.scrollTop); //设置滚动到的位置 // this.scrollTop=800; //读取元素的高度 // console.log(this.clientHeight) //意思就是内容总体的高度 - 滚动条的偏移值 === 元素的高度(包含内边)但不包含外边距,边框,以及滚动条 if(this.scrollHeight-this.scrollTop===this.clientHeight){ console.log("到达底部"); //移除disabled属性 checkbox.removeAttribute('disabled') } }) </script> </body> </html>
Okay, today I suddenly saw this API on mdn. I thought about it
Element.scrollTop
Have you learned it? Hurry up and give it a try.
Related recommendations:
Implementation of the div internal scroll bar scrolling to the bottom and top functions
jquery page scrolling to the bottom Automatically load plug-in collection_jquery
Javascript implements code for DIV scrolling to automatically scroll to the bottom_javascript skills
The above is the detailed content of Detailed explanation of js to determine whether the content area is scrolled to the bottom. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

JavaScript is a programming language widely used in web development, while WebSocket is a network protocol used for real-time communication. Combining the powerful functions of the two, we can create an efficient real-time image processing system. This article will introduce how to implement this system using JavaScript and WebSocket, and provide specific code examples. First, we need to clarify the requirements and goals of the real-time image processing system. Suppose we have a camera device that can collect real-time image data
