


This example should be said to be very simple, and it can also be processed directly using jQuery methods. However, the bottom layer of this article is processed using native js. If you encounter some small knowledge points, you can analyze them and it will be worthwhile.
The principle is very simple, just add a scroll event to the window. Each time the browser triggers the scroll event, it will determine whether it has scrolled to the bottom of the browser, and if it reaches the bottom, load new data. The key is to calculate whether the scroll bar has scrolled to the bottom of the browser. The algorithm is as follows
Scroll bar rolled up height + window height> total height of document + 50/*I will take the height of the scrolling response area to 50px*/; if this judgment is true means the scroll bar has scrolled to the bottom.
Example
<style type="text/css"> html,body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, button, textarea, p, blockquote, th, td{ margin: 0; padding:0; } *{ -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .waterfllow-loading{ z-index: 2000; display:none; } .waterfllow-loading.active{ display:block; } .waterfllow-loading img.loading-progress{ position: fixed; /*设置等待条水平居于窗口正中*/ margin-left: auto; margin-right: auto; left: 0; right: 0; /*不能设置margin-top:auto和margin-bottom:auto否则IE下bottom就不顶用了*/ bottom: 30px; } </style> <div class="waterfllow-loading"> <img class="loading-progress lazy" src="/static/imghwm/default1.png" data-src="busy.gif" alt="js implements the scroll bar to scroll to the bottom of the page and continue loading_javascript skills" > </div> <script type="text/javascript"> //图片查询中正对浏览器主页面滚动事件处理(瀑布流)。只能使用window方式绑定,使用document方式不起作用 $(window).on('scroll',function(){ if(scrollTop() + windowHeight() >= (documentHeight() - 50/*滚动响应区域高度取50px*/)){ waterallowData(); } }); function waterallowData(){ $('.waterfllow-loading').addClass('active'); /*$.ajax({ url:url, type:"post", data: params, success:function(data,textStatus,jQXHR){ //添加数据 ... //隐藏加载条 $('.waterfllow-loading.active').removeClass('active'); } });*/ }
Get the rolled-up height function at the top of the page
//获取页面顶部被卷起来的高度 function scrollTop(){ return Math.max( //chrome document.body.scrollTop, //firefox/IE document.documentElement.scrollTop); }
Chrome browser and Firefox/IE have different understandings of whether the scroll bar belongs to body or html, resulting in different processing.
Get the total height of the page document
//获取页面文档的总高度 function documentHeight(){ //现代浏览器(IE9+和其他浏览器)和IE8的document.body.scrollHeight和document.documentElement.scrollHeight都可以 return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight); }
This algorithm is consistent with jQuery’s method of calculating document height.
Get the height of the page browser viewport
function windowHeight(){ return (document.compatMode == "CSS1Compat")? document.documentElement.clientHeight: document.body.clientHeight; }
What needs to be explained here is document.compatMode. It's very strange, and it seems that I have never encountered it in general.
document.compatMode has two values: "BackCompat" and "CSS1Compat". The official explanation is BackCompat: Standard compatibility mode is turned off. CSS1Compat: Standards compatibility mode is turned on.
IE's rendering of the box model is very different between Standards Mode and Quirks Mode. The interpretation of the box model in Standards Mode is the same as that of other standard browsers, but there is a big difference in Quirks Mode. Without declaring Doctype, IE defaults to Quirks Mode.
Give an example to illustrate the difference between the two modes.
When document.compatMode is equal to "BackCompat", the browser client area width is document.body.clientWidth;
When document.compatMode is equal to CSS1Compat, the browser client area width is document.documentElement.clientWidth.
There are other similar attributes. I won’t go into details here, but we can foresee that the two modes will cause the cornerstones of IE rendering to change. You can imagine how different the buildings constructed will be.
So please declare Doctype for each page is not only a good habit, but also a necessary process. Quirks Mode can go into the trash.
Ok, here’s the complete code, with a small example (no data refresh in the background, just a waiting bar)
<!DOCTYPE html> <html lang="ch-cn"> <head> <meta charset="utf-8"> <script type="text/javascript" src='jquery-1.9.1.js'></script> <style type="text/css"> html,body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, button, textarea, p, blockquote, th, td{ margin: 0; padding:0; } *{ -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .waterfllow-loading{ z-index: 2000; display:none; } .waterfllow-loading.active{ display:block; } .waterfllow-loading img.loading-progress{ position: fixed; /*设置等待条水平居于窗口正中*/ margin-left: auto; margin-right: auto; left: 0; right: 0; /*不能设置margin-top:auto和margin-bottom:auto否则IE下bottom就不顶用了*/ bottom: 30px; } </style> </head> <body style="background:#ff0;height:1000px;"> <div class="waterfllow-loading"> <img class="loading-progress lazy" src="/static/imghwm/default1.png" data-src="busy.gif" alt="js implements the scroll bar to scroll to the bottom of the page and continue loading_javascript skills" > </div> </body> <script type="text/javascript"> //获取页面顶部被卷起来的高度 function scrollTop(){ return Math.max( //chrome document.body.scrollTop, //firefox/IE document.documentElement.scrollTop); } //获取页面文档的总高度 function documentHeight(){ //现代浏览器(IE9+和其他浏览器)和IE8的document.body.scrollHeight和document.documentElement.scrollHeight都可以 return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight); } //获取页面浏览器视口的高度 function windowHeight(){ //document.compatMode有两个取值。BackCompat:标准兼容模式关闭。CSS1Compat:标准兼容模式开启。 return (document.compatMode == "CSS1Compat")? document.documentElement.clientHeight: document.body.clientHeight; } </script> <script type="text/javascript"> //图片查询中正对浏览器主页面滚动事件处理(瀑布流)。只能使用window方式绑定,使用document方式不起作用 $(window).on('scroll',function(){ if(scrollTop() + windowHeight() >= (documentHeight() - 50/*滚动响应区域高度取50px*/)){ waterallowData(); } }); function waterallowData(){ $('.waterfllow-loading').addClass('active'); /*$.ajax({ url:url, type:"post", data: params, success:function(data,textStatus,jQXHR){ //添加数据 ... //隐藏加载条 $('.waterfllow-loading.active').removeClass('active'); } });*/ } </script> </html>
is
The above is an example of how to scroll to the bottom of the page and continue loading. I hope it will be helpful to everyone's learning.

如何使用JS和百度地图实现地图平移功能百度地图是一款广泛使用的地图服务平台,在Web开发中经常用于展示地理信息、定位等功能。本文将介绍如何使用JS和百度地图API实现地图平移功能,并提供具体的代码示例。一、准备工作使用百度地图API前,首先需要在百度地图开放平台(http://lbsyun.baidu.com/)上申请一个开发者账号,并创建一个应用。创建完成

如何使用JS和百度地图实现地图多边形绘制功能在现代网页开发中,地图应用已经成为常见的功能之一。而地图上绘制多边形,可以帮助我们将特定区域进行标记,方便用户进行查看和分析。本文将介绍如何使用JS和百度地图API实现地图多边形绘制功能,并提供具体的代码示例。首先,我们需要引入百度地图API。可以利用以下代码在HTML文件中导入百度地图API的JavaScript

js字符串转数组的方法:1、使用“split()”方法,可以根据指定的分隔符将字符串分割成数组元素;2、使用“Array.from()”方法,可以将可迭代对象或类数组对象转换成真正的数组;3、使用for循环遍历,将每个字符依次添加到数组中;4、使用“Array.split()”方法,通过调用“Array.prototype.forEach()”将一个字符串拆分成数组的快捷方式。

如何使用JS和百度地图实现地图热力图功能简介:随着互联网和移动设备的迅速发展,地图成为了一种普遍的应用场景。而热力图作为一种可视化的展示方式,能够帮助我们更直观地了解数据的分布情况。本文将介绍如何使用JS和百度地图API来实现地图热力图的功能,并提供具体的代码示例。准备工作:在开始之前,你需要准备以下事项:一个百度开发者账号,并创建一个应用,获取到相应的AP

js中new操作符做了:1、创建一个空对象,这个新对象将成为函数的实例;2、将新对象的原型链接到构造函数的原型对象,这样新对象就可以访问构造函数原型对象中定义的属性和方法;3、将构造函数的作用域赋给新对象,这样新对象就可以通过this关键字来引用构造函数中的属性和方法;4、执行构造函数中的代码,构造函数中的代码将用于初始化新对象的属性和方法;5、如果构造函数中没有返回等等。

这篇文章主要为大家详细介绍了js实现打字小游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。

php在特定情况下可以读js内部的数组。其方法是:1、在JavaScript中,创建一个包含需要传递给PHP的数组的变量;2、使用Ajax技术将该数组发送给PHP脚本。可以使用原生的JavaScript代码或者使用基于Ajax的JavaScript库如jQuery等;3、在PHP脚本中,接收传递过来的数组数据,并进行相应的处理即可。

js全称JavaScript,是一种具有函数优先的轻量级,直译式、解释型或即时编译型的高级编程语言,是一种属于网络的高级脚本语言;JavaScript基于原型编程、多范式的动态脚本语言,并且支持面向对象、命令式和声明式,如函数式编程。


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
