


JavaScript implements waterfall flow effect of automatic image loading_javascript skills
Let me show you the renderings first:
Pictures can be automatically loaded and displayed when you slide down the web page.
The box model for holding pictures is as follows:
<div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/8.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div>
Set img-width to 150px, then add padding and shadow effects to box_img, set the outer margin of box to 0, and add padding. The width of the box is stretched by img-width and margins. That is to say, there is no spacing between the boxes, but there is some margin effect inside the box. In this way, there is no need to consider the margin issue when setting the position in js, and just call the width of the box directly.
Set the position of the div holding all the boxes to relative, so that when setting the top value or left value, you don’t need to consider the outermost margin attribute.
Place the picture: Get the height of the first row of pictures and store them in the array. Set the position of the next pictures to absolute and place them below the picture with the smallest height. Then set top and left, and minimize the array. value plus the height of the newly placed image. That is to say, except for the first row of pictures originally placed in HTML, all other pictures are repositioned in js.
When the page is slid to the bottom, the event function is triggered, and then some pictures are placed to ensure unlimited loading of pictures.
HTML file:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-"> <title></title> <link rel="stylesheet" href="waterfall.css" type="text/css"> <script src="waterfall.js"></script> </head> <body> <div id="content"> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box" > <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box" > <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box" > <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box" > <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box"> <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> <div class="box" > <div class="box_img"> <img src="/static/imghwm/default1.png" data-src="Img/.jpg" class="lazy" alt="JavaScript implements waterfall flow effect of automatic image loading_javascript skills" > </div> </div> </div> </body> </html>
CSS file:
*{ margin: ; padding:; } #content{ position: relative; background-color: #; } .box{ padding: px; float: left; } .box_img{ padding: px; border: px solid #cccccc; box-shadow: px #cccccc; border-radius: px; } img{ width: px; height: auto; }
js file:
The Math.floor() function can round down.
Math.min.apply(null,heightArr); The function can obtain the minimum value of the heightArr array.
Window.onscroll=function(){}; This function is triggered when the page is scrolled.
document.documentElement.clientHeight; the height displayed by the browser.
document.documentElement.scrollTop; sliding distance.
/** * Created by asua on 2016/4/9. */ window.onload=function(){ imgLocation("content","box"); var lodeImage={"Date":[{"src":"1.jpg"},{"src":"2.jpg"},{"src":"3.jpg"},{"src":"4.jpg"},{"src":"5.jpg"},{"src":"6.jpg"},{"src":"7.jpg"},{"src":"8.jpg"},{"src":"9.jpg"},{"src":"10.jpg"},]} window.onscroll=function(){ if(checkFlag()){ for(var i=0;i<lodeImage.Date.length;i++){ var box=document.createElement("div"); box.className="box"; var cparent=document.getElementById("content"); cparent.appendChild(box); var box_img=document.createElement("div"); box_img.className="box_img"; box.appendChild(box_img); var img=document.createElement("img"); img.src="Img/"+lodeImage.Date[i].src; box_img.appendChild(img); } imgLocation("content","box"); } } } function checkFlag(){ var cparent=document.getElementById("content"); var ccontent=getChildElement(cparent,"box"); var lastContentHeight=ccontent[ccontent.length-1].offsetTop; var scrollHeight=document.documentElement.scrollTop||document.body.scrollTop; var pageHeight=document.documentElement.clientHeight||document.body.clientHeight; console.log(lastContentHeight+":"+scrollHeight+":"+pageHeight); if(lastContentHeight<scrollHeight+pageHeight){ return true; } } function imgLocation(parent,child){ var cparent=document.getElementById(parent); var ccontent=getChildElement(cparent,child); var imgwidth=ccontent[0].offsetWidth; var cols=Math.floor(document.documentElement.clientWidth/imgwidth); cparent.style.cssText="width:"+imgwidth*cols+"px;margin:30px auto"; var heightArr=[]; for(var i=0;i<ccontent.length;i++){ if(i<cols){ heightArr.push(ccontent[i].offsetHeight); }else{ var minHeight=Math.min.apply(null,heightArr); var minIndex=getMinIndex(heightArr,minHeight); ccontent[i].style.position="absolute"; ccontent[i].style.top=minHeight+"px"; ccontent[i].style.left=ccontent[minIndex].offsetLeft+"px"; heightArr[minIndex]+=ccontent[i].offsetHeight; } } } function getMinIndex(heightArr,minHeight){ for(var i=0;i<heightArr.length;i++){ if(heightArr[i]==minHeight){ return i; } } } function getChildElement(parent,content){ var contentArr=[]; var allcontent=parent.getElementsByTagName("*"); for(var i=0;i<allcontent.length;i++){ if(allcontent[i].className==content){ contentArr.push(allcontent[i]); } } return contentArr; }
Okay, this is the introduction to the waterfall flow effect code for automatic image loading using js. I hope it will be helpful to you!

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing


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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

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