瀑布流布局非常适合大量图片的展示,一改过去裁剪图片尺寸统一的排版,每张图片都能完全展示,并错落有致,让人眼前一亮。
-
注意事项:
-
项目中的 img 元素的 width 和 height 属性需要写,否则定位会不准确。
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Wookmark 瀑布流布局 »</title>
<link rel="stylesheet" href="css/demo.css">
<link rel="stylesheet" href="css/layout.css">
</head>
<body>
<div class="wrap">
<div class="main">
<div class="inwrap">
<h1>jQuery Wookmark 瀑布流布局</h1>
<div class="detail">
<p>所有图片的宽度和高度都已设置,这样可以在图片加载之前就进行布局。</p>
<p>调整浏览器窗口大小,或者单击列表中的项目时,会触发列表布局更新。</p>
</div>
<div class="example">
<div id="main" role="main">
<ul id="tiles">
<!-- These are our grid blocks -->
<li><img src="images/image_1.jpg" width="200" height="283"><p>1</p></li>
<li><img src="images/image_2.jpg" width="200" height="300"><p>2</p></li>
<li><img src="images/image_3.jpg" width="200" height="252"><p>3</p></li>
<li><img src="images/image_4.jpg" width="200" height="158"><p>4</p></li>
<li><img src="images/image_5.jpg" width="200" height="300"><p>5</p></li>
<li><img src="images/image_6.jpg" width="200" height="297"><p>6</p></li>
<li><img src="images/image_7.jpg" width="200" height="200"><p>7</p></li>
<li><img src="images/image_8.jpg" width="200" height="200"><p>8</p></li>
<li><img src="images/image_9.jpg" width="200" height="398"><p>9</p></li>
<li><img src="images/image_10.jpg" width="200" height="267"><p>10</p></li>
<li><img src="images/image_1.jpg" width="200" height="283"><p>11</p></li>
<li><img src="images/image_2.jpg" width="200" height="300"><p>12</p></li>
<li><img src="images/image_3.jpg" width="200" height="252"><p>13</p></li>
<li><img src="images/image_4.jpg" width="200" height="158"><p>14</p></li>
<li><img src="images/image_5.jpg" width="200" height="300"><p>15</p></li>
<li><img src="images/image_6.jpg" width="200" height="297"><p>16</p></li>
<li><img src="images/image_7.jpg" width="200" height="200"><p>17</p></li>
<li><img src="images/image_8.jpg" width="200" height="200"><p>18</p></li>
<li><img src="images/image_9.jpg" width="200" height="398"><p>19</p></li>
<li><img src="images/image_10.jpg" width="200" height="267"><p>20</p></li>
<li><img src="images/image_1.jpg" width="200" height="283"><p>21</p></li>
<li><img src="images/image_2.jpg" width="200" height="300"><p>22</p></li>
<li><img src="images/image_3.jpg" width="200" height="252"><p>23</p></li>
<li><img src="images/image_4.jpg" width="200" height="158"><p>24</p></li>
<li><img src="images/image_5.jpg" width="200" height="300"><p>25</p></li>
<li><img src="images/image_6.jpg" width="200" height="297"><p>26</p></li>
<li><img src="images/image_7.jpg" width="200" height="200"><p>27</p></li>
<li><img src="images/image_8.jpg" width="200" height="200"><p>28</p></li>
<li><img src="images/image_9.jpg" width="200" height="398"><p>29</p></li>
<li><img src="images/image_10.jpg" width="200" height="267"><p>30</p></li>
<!-- End of grid blocks -->
</ul>
</div>
</div>
</div>
</div>
</div>
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/jquery.wookmark.min.js"></script>
<script>
(function ($){
var handler = $('#tiles li');
handler.wookmark({
// Prepare layout options.
autoResize: true, // This will auto-update the layout when the browser window is resized.
container: $('#main'), // Optional, used for some extra CSS styling
offset: 5, // Optional, the distance between grid items
outerOffset: 10, // Optional, the distance to the containers border
itemWidth: 210 // Optional, the width of a grid item
});
// Capture clicks on grid items.
handler.click(function(){
// Randomize the height of the clicked item.
var newHeight = $('img', this).height() + Math.round(Math.random() * 300 + 30);
$(this).css('height', newHeight+'px');
// Update the layout.
handler.wookmark();
});
})(jQuery);
</script>
</body>
</html>
IE:http://localhost:8080/JavaRsa/MyWeekMark.jsp
运行效果:
demo已上传至我的资源
参数说明
参考: http://code.ciaoca.com/jquery/wookmark/demo/load-images.html