打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
javascript – 当第一个砌体’item’被隐藏时,所有剩余的项目形成一个列

我正在尝试将Masonry用于一个项目,但我对JS缺乏经验.我遇到了一个问题,即隐藏砌体网格中的第一个项目导致其余的网格项形成一个列.

我可以隐藏和显示我想要的其他项目,而不是它看起来的第一个.

下面的编码重现问题,按“创建”以形成砌体布局,然后“隐藏”以隐藏具有“特殊”类的div …

http://codepen.io/anon/pen/ByxmMv

从第一个div中删除“特殊”类将演示所需的布局行为.

我希望我只是做错了但如果我不能有人展示出一种解决方法?

谢谢你的帮助.

 <!DOCTYPE html><html><head>  <meta charset="UTF-8">  <title>Masonry</title>  <link rel="stylesheet" href="css/style.css" media="screen" type="text/css" />  <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>  <script src="//masonry.desandro.com/masonry.pkgd.js"></script>  <script type="text/javascript">    function hide() {      $(".special").hide();      msnry.layout();    }    function show() {      $(".special").show();      msnry.layout();    }    function create() {      container = document.querySelector('#container');      msnry = new Masonry( container, {        itemSelector: ".item",        isAnimated: true      });    }    function destroy() {      msnry.destroy();    }  </script>  <style type="text/css">    #container {      background: #EEE;      max-width: 80%;      margin: 10px;    }    .item {      width:  150px;      height: 150px;      float: left;      background: green;      border: 2px solid #333;      margin: 10px;    }    .item:nth-child(3n){      height: 100px;    }    .special {      background:orange;    }  </style></head><body>  <button onclick="create()">Create</button>  <button onclick="destroy()">Destroy</button>  <button onclick="hide()">Hide</button>  <button onclick="show()">Show</button>  <div id="container">    <div class="item special"></div>    <div class="item special"></div>    <div class="item special"></div>    <div class="item"></div>    <div class="item special"></div>    <div class="item special"></div>    <div class="item"></div>    <div class="item special"></div>    <div class="item delete"></div>    <div class="item"></div>    <div class="item special"></div>    <div class="item"></div>    <div class="item"></div>    <div class="item"></div>    <div class="item"></div>  </div></body></html>

解决方法:

您可以添加’sizer’元素以获得适当的宽度:

        msnry = new Masonry( container, {            itemSelector: ".item",            columnWidth: '.sizer',            isAnimated: true        });

http://codepen.io/herihehe/full/ravYEL/

来源:https://www.icode9.com/content-1-292901.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
javascript
超平滑滚动的jQuery标签分栏切换效果
顶部选项卡切换单web
使用 HTML、CSS 和 JS 创建响应式可过滤的游戏+工具展示页面
jQuery:1.5.5.1,多选择单一条件查询(search)
flex如何实现头部固定,内容区域滚动
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服