/
index.html
170 lines (154 loc) · 6.41 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>瀑布流</title>
</head>
<style>
* {
margin: 0;
padding: 0;
}
.switch {
text-align: center;
}
.switch button {
height: 30px;
width: 100px;
}
.waterfall-container {
}
.box {
border: 1px dashed lightgray;
}
.box-content {
border: 1px dashed brown;
}
.box-content img {
width: 100%;
border: 1px solid black;
box-sizing: border-box;
}
.box-content p {
font-size: 14px;
box-sizing: border-box;
}
</style>
<body>
<div class="switch">
<button>关闭瀑布流</button>
</div>
<div class="waterfall-container">
<div class="box">
<div class="box-content">
<img src="http://cdn2.mhpbooks.com/2016/02/google.jpg">
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p>
</div>
</div>
<div class="box">
<div class="box-content">
<img src="https://www.google.com/landing/2step/images/why-need-img-2.png">
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p>
</div>
</div>
<div class="box">
<div class="box-content">
<img src="https://4.bp.blogspot.com/-Nyfdpymc_Lo/VkQw-nJ79mI/AAAAAAAARYg/6o9VeoTvu-I/s1600-r/logo_chrome.png"
>
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p></div>
</div>
<div class="box">
<div class="box-content">
<img src="http://lh3.googleusercontent.com/jN9tX6dCJ6_XL9E4K1KCO2Tuwe9_rYUbwv723eu6XGI0PWGLcPs0259VscOu249PPKKcU5AOXrq6JnleEaoK6K_JvZ2PY9lw3pMApzOpTQ=s660"
>
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p></div>
</div>
<div class="box">
<div class="box-content">
<img src="http://i1.sinaimg.cn/IT/2013/0320/U5385P2DT20130320080117.jpg">
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p></div>
</div>
<div class="box">
<div class="box-content">
<img src="http://www.people.com.cn/mediafile/pic/20150906/81/15788599594280374761.jpg">
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p></div>
</div>
<div class="box">
<div class="box-content">
<img src="http://www.kuqin.com/upimg/topic/google.jpg">
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p></div>
</div>
<div class="box">
<div class="box-content">
<img src="http://www.xjp.cc/img.xjp.cc/2010/07/google-china.jpg">
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p></div>
</div>
<div class="box">
<div class="box-content">
<img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcT6PwQ_Z2SO1lADWUw--QxVOFyHTr5JVRNuE89u5s99xoGerxK55A"
>
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p></div>
</div>
<div class="box">
<div class="box-content">
<img src="http://is4.mzstatic.com/image/thumb/Purple62/v4/c0/41/29/c04129a1-9b56-88b6-ae59-f424c6d9d343/source/512x512bb.jpg"
>
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p></div>
</div>
<div class="box">
<div class="box-content">
<img src="http://images.ifanr.cn/wp-content/uploads/2016/05/eric-schmidt.jpg">
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p></div>
</div>
<div class="box">
<div class="box-content">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTjr4L3m4efhuQK-6-DoNh4AmwIV4gIaVY0mb1SABPTTdi3SW60"
>
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p></div>
</div>
<div class="box">
<div class="box-content">
<img src="http://pad2.whstatic.com/images/thumb/f/f9/Delete-Google-Browsing-History-Step-4-Version-4.jpg/728px-Delete-Google-Browsing-History-Step-4-Version-4.jpg"
>
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p></div>
</div>
<div class="box">
<div class="box-content">
<img src="https://www.google.com.hk/intl/zh-CN/mobile/google-mobile-app/googlesuggest.jpg">
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p></div>
</div>
<div class="box">
<div class="box-content">
<img src="http://img.ithome.com/newsuploadfiles/2016/10/20161005_014140_718.png">
<p>谷歌公司成立于1998年9月4日,被公认为全球最大的搜索引擎。</p></div>
</div>
</div>
</body>
<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<script src="js/myWaterfall.js"></script>
<script>
$(function () {
//初始化开启瀑布流布局
$(".waterfall-container").waterfall({
autoResize: true, // 当浏览器大小改变时是否自动调整
offsetWidth: 5, // 每个元素之间的宽度距离(不加单位默认px)
offsetHeight: 20, // 每个元素之间的高度距离(不加单位默认px)
itemWidth: 200, // 每个元素的宽度,瀑布流高度是不限制的,所以只要宽度固定就可以了
colNumber: 4, // 规定一行有几个元素,只有autoResize: false才生效
colNumberMin: 2, // 规定一行最小有几个元素
colNumberMax: 5, // 规定一行最大有几个元素
resizeDelay: 0 // 自动调整延迟时间,一般情况下不需要设置,默认的就好了
});
//开关控制开关瀑布流布局
$(".switch button").click(function () {
if ($(this).html() == "开启瀑布流") {
$(".waterfall-container").waterfall('init');
$(this).html("关闭瀑布流");
} else if ($(this).html() == "关闭瀑布流") {
$(".waterfall-container").waterfall('destroy');
$(this).html("开启瀑布流");
}
});
});
</script>
</html>