jQuery瀑布流插件masonry

时间:2023-04-18 14:12:20

项目要做荣誉证书的排版,宽度是统一的,但是高度不一致

采用瀑布流的效果来实现

默认先实现前15张,点击按钮再加载全部剩下的数据

效果图

jQuery瀑布流插件masonry

首先是html部分,写好样式

<!-- 荣誉资质 -->
<div class="about_honor">
<div class="container">
<h2>
<img src="/templates/img/honor_img1.png" />
<p>展望未来,我们满怀信心。xx网络的点滴进步均来源于广大客户的不断支持。</p>
</h2>
<ul class="box-container" id="main-box">
<!-- 加载前15张图片 -->
<?php
$info=mysqli_query($con,"SELECT * FROM `wit_honor` order by `order` limit 15");
while($row=mysqli_fetch_array($info)){ ?>
<li class="box wow fadeInUp" data-wow-delay=".1s"><img src="/templates/images/honor/<?php echo $row['honor_imgurl'];?>" /></li>
<?php
}
//加载15张以后的全部图片
$info2=mysqli_query($con,"SELECT * FROM `wit_honor` order by `order` limit 15,30 ");
while($row2=mysqli_fetch_array($info2)){
?>
<li class="box new-box"><img src="/templates/images/honor/<?php echo $row2['honor_imgurl'];?>" /></li>
<?php
}
?> </ul>
<div class="clearfix"></div>
<div class="honor_loading">
<div class="button--loading">
<i>·</i>
<i>·</i>
<i>·</i>
</div>
查看全部证书
</div>
</div>
</div>

因为php很烂,所以直接把代码嵌里面了,哈哈哈

css部分大概这样

/*荣誉资质*/
.about_honor{width:100%; float: left; position: relative; background: #2d323c; padding: 50px 0;}
.about_honor ul li{width:20%; float: left; text-align: center; padding-bottom: 15px; -webkit-flex:;flex:;}
.about_honor li img{border: 13px #ffff solid; width:85%;}
.about_honor h2{ text-align:center;}
.about_honor p{ font-size:18px; color: #fff; padding-bottom: 30px;} .honor_loading {width:100px; text-align: center; margin:0 auto; font-size:16px; color: #fff; line-height: 35px;}
.honor_loading a {position: relative;display: block;color: #74777b;padding: 1em 1em 2.5em 1em;text-decoration: none;}
.honor_loading a:hover {text-decoration: none;color: #2cc185;background-color: #e7ecea;transition: 0.3s;}
.honor_more{z-index:;} .button--loading{width:60px; line-height: 50px; margin:0 auto; background: #fff; color: #e37a40;}
.button--loading i { font-size:24px; font-weight: bold; font-style:normal;
-webkit-animation: fadeInOut 0.3s ease-in infinite alternate forwards;
animation: fadeInOut 0.3s ease-in infinite alternate forwards;}
.button--loading i:nth-child(2) {-webkit-animation-delay: 0.1s;animation-delay: 0.1s;}
.button--loading i:nth-child(3) {-webkit-animation-delay: 0.2s;animation-delay: 0.2s;} @-webkit-keyframes fadeInOut {
from {opacity:;}
to {opacity:;}
} @keyframes fadeInOut {
from {opacity:;}
to {opacity:;}
}

然后先引入js

<script src="/templates/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/templates/js/jquery.masonry.min.js"></script>

再是实现效果的部分

  <script type="text/javascript">
$(document).ready(function(){
//这段是瀑布流插件的色值
var $container = $('.box-container');//获取总容器
$container.imagesLoaded(function(){
$container.masonry({
itemSelector: '.box',//获取每张图片的容器
columnWidth: 1//每两列之间的间隙为5像素
});
}); //隐藏15张以后的图
$(".new-box").hide();
//图片容器高度设置
$(".about_honor").css({
"height":"1500px"
});
//查看全部按钮定位
$(".honor_loading").css({
"position":"absolute",
"bottom":"59px",
"left":"50%",
"margin-left":"-30px"
}); //点击查看全部
$(".honor_loading").click(function() {
//显示15张以后的图
$(".new-box").slideToggle(1000);
//图片容器高度复原
$(".about_honor").css({
"height":""
});
//查看全部按钮隐藏
$(".honor_loading").hide();
}); });
</script>

不太会代码封装,写的比较散啦~