We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
css简单实现
.container{ Columns-width: 300px; Column-gap: 5px; } .container div { Width: 300px; margin: 5px; }
js实现方式 html页面
js实现方式
html页面
<div class="container" id="container"> <div class="box"> <div class="box_img"> <img src="./img/1.jpg"> </div> </div> <div class="box"> <div class="box_img"> <img src="./img/2.jpg"> </div> </div> <div class="box"> <div class="box_img"> <img src="./img/3.jpg"> </div> </div> <!-- .....假设有多张图片 --> </div>
css样式 - 使用float布局
css样式
*{ margin: 0px; padding: 0px; } .container { position: relative; } .box { padding: 5px; float: left; } .box_img { padding: 5px; border: 1px solid #cccccc; box-shadow: 0 0 5px #cccccc; border-radius: 5px; } .box_img img { width: 150px; height: auto; }
效果图
dom中获取图片的高度与宽度
offsetHeight
offsetWidth
offsetLeft
解决问题
document.documentElement.clientWidth / imgWidth
BoxHeightAr数组
offsetTop
scrollTop
clientHeight
判断条件
function checkFlag() { var cparent = document.getElementById('container'); var ccontent = getChildElement(cparent, 'box'); // 最后一张图片,距顶部的宽度 // console.log(ccontent[ccontent.length - 1].offsetTop); var lastContentHeight = ccontent[ccontent.length - 1].offsetTop; // 图片滑动的距离 var scrollTop = document.documentElement.scrollTop|| document.body.scrollTop; // 页面的高度 var pageHeight = document.documentElement.clientHeight || document.body.clientHeight; console.log(lastContentHeight, scrollTop, pageHeight) if(lastContentHeight < scrollTop + pageHeight) { return true; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
如何使用js实现瀑布流图片
css简单实现
js实现方式
html页面
css样式
- 使用float布局效果图
dom中获取图片的高度与宽度
offsetHeight
offsetWidth
offsetLeft
解决问题
document.documentElement.clientWidth / imgWidth
BoxHeightAr数组
(初始化是第一列的高度)offsetTop
- 利用获取最后一图片,屏幕距离顶部的距离scrollTop
- 图片滑动的距离clientHeight
- 浏览器当前的高度判断条件
- lastContentHeight < scrollTop + pageHeightThe text was updated successfully, but these errors were encountered: