This article shares the specific code of JS to realize the picture waterfall flow for your reference. The specific content is as follows process: 1. Create a module bigblock to store all the pictures. <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>photo waterfall</title> <style> *{ margin:0; padding:0; } body{ /* background: #ebebeb;*/ background: url(./img/bging2.jpg); background-size:100% ; height:100%; } .bigblock { position: relative; width:650px; min-height: 200px; background: #fff; margin:auto; } .smallblock{ position:absolute; width:100px; border-radius:5px; box-shadow: 0 0 7px #89c8eb; box-sizing: border-box; overflow: hidden; } .photo{ width:100%; vertical-align: middle; } </style> </head> <body> <div class="bigblock"> </div> <script> var Big = document.getElementsByClassName ("bigblock")[0]; var ele=[]; var num=6; var bghight=0; var start=0; var image_img=["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg", "6.jpg", "7.jpg", "9.jpg", "10.jpg","11.jpg","12.jpg","13.jpg","14.jpg","15.jpg","16.jpg","17.jpg"]; for(var i=0;i<50;i++){ list(); } function list(n){ var small = document.createElement("div"); var image = document.createElement("img"); small.className="smallblock"; image.className="photo"; image.src="./img/"+image_img[parseInt(Math.random()* image_img.length)]; //0-12 ele.push(small); Big.appendChild(small); small.appendChild (image); } function set_position(){ for(var i=start;i<ele.length;i++){ //Set the position of each picture var settop=i <num ? 0: ele[i-num].offsetHeight +10 + ele[i-num].offsetTop; ele[i].style.top=settop+"px"; var setleft = i %num * ele[i].offsetWidth + (i % num) * 10; ele[i].style.left=setleft+"px"; //Get the background height bghight =(ele[i].offsetHeight +ele[i].offsetTop)>bghight ? ele[i].offsetHeight +ele[i].offsetTop :bghight ; Big.style.height =bghight + "px"; } } window.onload = function(){ set_position(); //Add the browser's scroll bar event this.addEventListener ("scroll", function() { var b_height=document.body.clientHeight; if(parseInt (this.pageYOffset + this.innerHeight ) > b_height - 10 ){ start =ele.length; for(i=0;i<30;i++){ list(); } set_position (); } // console.log(b_height); //The visible height of the body, variable // console.log(this.pageYOffset); //The upper offset of the scroll bar // console.log(this.innerHeight); //The height of the browser's visible area}) } </script> </body> </html> The picture is not a dynamic picture, so you can't see any effect, but the code is correct, you can give it a try. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Setting the engine MyISAM/InnoDB when creating a data table in MySQL
>>: js to realize web message board function
Table of contents Comprehensive comparison From t...
CSS controls the printing style of web pages : Use...
FileReader is an important API for front-end file...
Text Shadow text-shadow: horizontal offset vertic...
1. Merge the margins of sibling elements The effe...
Preface Linux's file permission management is...
Table of contents 1. Main functions 2. Implementa...
This article shares the specific code of using ca...
Key Points The CSS resize property allows you to ...
Last night I wrote an essay about the browser ren...
Three tables are connected. Field a of table A co...
Table of contents Preface Reference Comparison Ma...
Table of contents 1. JavaScript uses canvas in HT...
1. Function Mainly used to preserve component sta...
Common methods for limiting input 1. To cancel the...