-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
187 lines (170 loc) · 4.42 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Waterfall.js</title>
</head>
<style>
* {
margin: 0;
padding: 0;
list-style: none;
}
.modal {
margin-top: 50px;
width: 520px;
height: 600px;
border: 1px solid;
overflow-y: scroll;
position: relative;
}
.load-more {
text-align: center;
margin: 30px auto;
}
</style>
<body>
<div style="margin: 20px">
<a href="https://codepen.io/iounini/pen/KyYPKe" target="_blank">position版本核心思路</a><br />
<a href="https://juejin.cn/post/6844904004720263176#heading-6" target="_blank">grid布局版本核心思路</a><br />
</div>
<div style="display: flex; justify-content: space-around;">
<div>
<h3>grid版本:</h3>
<div class="modal">
<ul id="waterfall-grid"></ul>
<div id="load-more-grid" class="load-more">
<button>加载更多</button>
</div>
</div>
</div>
<div>
<h3>position版本</h3>
<div class="modal">
<ul id="waterfall-position"></ul>
<div id="load-more-position" class="load-more">
<button>加载更多</button>
</div>
</div>
</div>
</div>
</body>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<!-- <script src="https://unpkg.com/browse/waterfalljs-layout@latest/dist/waterfalljs-layout.esm.js"></script> -->
<script src="../dist/waterfalljs-layout.min.js"></script>
<script type="text/javascript">
const images = [
"https://picsum.photos/640/200/?random",
"https://picsum.photos/360/640/?random",
"https://picsum.photos/480/720/?random",
"https://picsum.photos/480/640/?random",
"https://picsum.photos/360/?random",
"https://picsum.photos/360/520/?random",
"https://picsum.photos/520/360/?random",
"https://picsum.photos/520/360/?random",
"https://picsum.photos/520/360/?random",
"https://picsum.photos/720/640/?random"
]
function random(min, max) {
return min + Math.floor(Math.random() * (max - min + 1));
}
let num = 0
// 创建UI
function createView() {
var arr = new Array(9).fill('-')
var viewDom = ""
var templateDom = (index) => {
const imgSrc = `${images[index]}=${random(1, 10000)}`
num++
const image = ` <li><div><span>${num}</span><img src='${imgSrc}' /></div></li>`
const noImage = `<li><div style='height: ${random(100, 200)}px'><span>${num} --- 此block 没有图片</span></div></li>`
return Math.random() > 0.2 ? image : noImage
}
for (let i = 0; i < arr.length; i++) {
viewDom += templateDom(i)
}
return viewDom
}
</script>
<!-- grid 布局核心代码 -->
<script>
// 初始化插件
const wfGrid = Waterfall({
mode: 'grid',
el: '#waterfall-grid',
columnWidth: 236,
columnGap: 24,
rowGap: 24,
delay: 800,
customStyle: `#waterfall-grid li>div {
border-radius: 8px;
font-size: 20px;
overflow: hidden;
color: rgba(0, 0, 0, 0.6);
padding: 6px;
background: rgb(255, 255, 255);
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
transition: all 0.3s;
}
#waterfall-grid li>div:hover {
transform: translateY(-6px);
box-shadow: 0 30px 50px rgba(0, 0, 0, 0.3);
transition: all 0.3s;
}
#waterfall-grid li>div>img {
width: 100%
}`
})
var viewDom = createView()
$("#waterfall-grid").append(viewDom)
// 初始化加载
wfGrid.load()
// 加载更多
$('#load-more-grid').click(() => {
var viewDom = createView()
$("#waterfall-grid").append(viewDom)
wfGrid.load()
})
</script>
<!-- position布局核心代码 -->
<script>
const wfPosition = Waterfall({
mode: 'position',
el: '#waterfall-position',
columnWidth: 236,
columnGap: 24,
rowGap: 24,
delay: 800,
customStyle: `#waterfall-position li>div {
border-radius: 8px;
font-size: 20px;
overflow: hidden;
color: rgba(0, 0, 0, 0.6);
padding: 6px;
background: rgb(255, 255, 255);
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
transition: all 0.5s;
}
#waterfall-position li>div:hover {
transform: translateY(-6px);
box-shadow: 0 30px 50px rgba(0, 0, 0, 0.3);
transition: all 0.3s
}
#waterfall-position li>div>img {
width: 100%
}`
})
var viewDom = createView()
$("#waterfall-position").append(viewDom)
// 初始化加载
wfPosition.load()
// 加载更多
$('#load-more-position').click(() => {
var viewDom = createView()
$("#waterfall-position").append(viewDom)
wfPosition.load()
})
</script>
</html>