当前位置:网站首页>Native JS implements page scroll bar loading data and page drop-down loading content
Native JS implements page scroll bar loading data and page drop-down loading content
2022-06-27 10:39:00 【Cut potatoes into shreds】
One 、 Preface
Today's case is Scroll bar events , When the distance between the scroll bar and the bottom is less than a range value , Will automatically increase the height of the page , So as to achieve the effect of never drawing to the bottom .
Two 、scrollHeight、scrollTop and clientHeight The difference between
Full text height of web page
Distance from the top of the scroll bar ( The distance the scroll bar is rolled away )
The height of the screen you can see
because js They didn't give it to us The distance of the scroll bar from the bottom We need to calculate by ourselves use Full text height of web page subtract Distance from the top of the scroll bar Subtract the height of the screen you can see to get The distance of the scroll bar from the bottom 了 .
3、 ... and 、 Code
<style>
body{
padding-top: 2000px;
}
</style>
<body>
<script>
var body1 = document.getElementsByTagName("body")[0];
var step = 500;
var offsetx =0;
console.log(body1);
// body1.style.paddingBottom = 0;
// body1.style.paddingBottom =offsetx;
window.onscroll = function(){
// The full text of the web page is high
var pageHeight = document.documentElement.scrollHeight;
// The distance the scroll bar is rolled away
var stop = document.documentElement.scrollTop;
// The height of the screen you can see
var seeHeight = document.documentElement.clientHeight;
// Distance from the bottom
var bottom1 = pageHeight - stop - seeHeight;
// console.log(" Distance from the bottom "+ bottom1)
// console.log(" The full text of the web page is high "+pageHeight)
// console.log(" The distance the scroll bar is rolled away "+stop)
// console.log(" The height of the screen you can see "+seeHeight)
// console.log("---------")
// When the scroll bar is less than... From the bottom 200 It's triggered when
if(bottom1<=200){
offsetx+=step;
body1.style.paddingBottom = offsetx +"px";
// alert(" load ")
// document.write('111111111111111111111111')
}
//console.log(e)
}
</script>This is recorded for future use , I also hope the big guys can communicate more , Leave more messages , Point out my shortcomings !
You can study it if you need it !!
边栏推荐
- [tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)
- JS all network request modes
- torchvision. models._ utils. Intermediatelayergetter tutorial
- C apprentissage des langues - jour 12.
- Mail system (based on SMTP protocol and POP3 protocol -c language implementation)
- Support system of softswitch call center system
- C language learning day_ 06
- Leetcode to do questions
- In the three-tier architecture, at which layer is the database design implemented, not at the data storage layer?
- 实验笔记之——CARMEN (.log .clf)文件转换为rosbag
猜你喜欢

Comparison between new and old interfaces

.NET6接入Skywalking链路追踪完整流程

CPU design (single cycle and pipeline)

C any() and aii() methods

Oracle连接MySQL报错IM002

Future & CompletionService

Win10 shortcut key sorting

Product strength benchmarking seal /model 3, with 179800 pre-sales of Chang'an dark blue sl03

Future & CompletionService

CPU设计(单周期和流水线)
随机推荐
中科院微生物所招聘青年PI 20位,2百万安家费,千万启动经费(长期有效)
【TcaplusDB知识库】Tmonitor单机安装指引介绍(二)
[tcapulusdb knowledge base] tcapulusdb cluster management introduction
Go zero micro Service Practice Series (VII. How to optimize such a high demand)
微软云 (Microsoft Cloud) 技术概述
Explain the imaging principle of various optical instruments in detail
[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (I)
实验笔记之——CARMEN (.log .clf)文件转换为rosbag
[noodle classic] Yunze Technology
20 jeunes Pi recrutés par l'Institut de microbiologie de l'Académie chinoise des sciences, 2 millions de frais d'établissement et 10 millions de fonds de démarrage (à long terme)
Leetcode 729. 我的日程安排表 I(牛逼,已解决)
Ubuntu manually installing MySQL
记一次 .NET 某物管后台服务 卡死分析
[tcapulusdb knowledge base] tcapulusdb Model Management Introduction
Frequently asked questions about closures
Privacy computing fat offline prediction
Quelles sont les fonctions de base nécessaires au développement d'applications de commerce électronique en direct? Quelles sont les perspectives d'avenir?
如何在 Methodot 中部署 JupyterLab?
测试同学怎么参与codereview
flutter 微信分享