bootstrap配合Masonry外掛程式實現瀑布式布局,bootstrapmasonry

來源:互聯網
上載者:User

bootstrap配合Masonry外掛程式實現瀑布式布局,bootstrapmasonry

問題是這樣的,使用bootstrap的柵格進行布局的時候,如果大小超過了,會自動的轉到下一行,但是在顯示圖片的時候就會出現縫隙,下面介紹masonry進行縫隙的填補。

好,下面上貨。

1、首先是html

<html> <head>  <title>Title</title>  <meta charset="utf-8"/>  <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css"/>  <script type="text/javascript" src="jquery-2.1.4.min.js"></script>  <script type="text/javascript" src="bootstrap/masonry-docs.min.js"></script>  <script type="text/javascript" src="t.js"></script>  <style type="text/css">  .container-fluid {  padding: 20px;  }  .box {  margin-bottom: 20px;  float: left;  width: 220px;  }  .box img {  max-width: 100%  }  </style> </head> <body> <button class="btn btn-info">123</button> <div id="masonry" class="container-fluid">  <div class="box"><img src="img/p1.png">123</div>  <div class="box"><img src="img/p2.png">34444444444444444444</div>  <div class="box"><img src="img/p3.png">42234234</div>  <div class="box"><img src="img/p4.png">234</div>  <div class="box"><img src="img/p5.png">22222222222222</div>  <div class="box"><img src="img/p6.png">2321213</div> </div> </body> </html> 

然後是t.js

$(function() {  var $container = $('#masonry');  $container.imagesLoaded(function() {  $container.masonry({  itemSelector: '.box',  gutter: 20,  isAnimated: true,  });  }); }); 

最後是:

調整瀏覽器大小,讓圖片顯示成三列:

源碼下載:http://xiazai.jb51.net/201701/yuanma/bootstrappubu(jb51.net).rar

參考:http://www.bkjia.com/article/103444.htm

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.