-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdemo.html
280 lines (276 loc) · 11.1 KB
/
demo.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<!--
- Album - https://github.com/772807886/Album
- Created by Liming on 2016/5/5.
- Version: 1.2
-->
<!DOCTYPE html>
<html lang="zh-HanS">
<head>
<meta charset="UTF-8"/>
<meta name="renderer" content="webkit"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport"
content="width=device-width,height=device-height,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
<meta name="author" content="金黎明,Liming Jin,[email protected],TianJin China"/>
<title>Album</title>
<link rel="stylesheet" href="./css/album.min.css"/>
<script src="./js/album.js"></script>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0;
}
/** 操作面板整体 */
#control {
background-color: rgba(150, 150, 150, 0.7);
width: 650px;
position: fixed;
z-index: 101;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/** 和操作面板标题 */
#control-title {
color: white;
background-color: blue;
padding: 5px;
width: 640px;
height: 20px;
cursor: move;
}
/** 操作面板操作区 */
#control-main {
overflow: auto;
width: 640px;
padding: 5px;
text-align: center;
}
input {
text-align: center;
}
</style>
</head>
<body>
<div id="album" style="width: 100%; height: 100%; overflow-y: auto;"></div>
<!-- 操作面板 -->
<div id="control">
<div id="control-title">Control 操作面板 Library Version: 1.2</div>
<div id="control-main">
<div>
图片源:
<input id="A" type="radio" name="source"/><label for="A">LOREMPixel</label>
<input id="B" type="radio" name="source" checked="checked"/><label for="B">Place Hold It(Faster)</label>
</div>
<div>
<input id="w" type="number" min="1" placeholder="width" value="520"/>×
<input id="h" type="number" min="1" placeholder="height" value="250"/>
<button onclick="addImg()">添加图片</button>
<button onclick="addRandom()">添加随机大小图片</button>
</div>
<div>
<input id="auto" type="checkbox" checked="checked" onclick="resizeUpdate();"/>
<label for="auto">容器尺寸变化自适应</label>
</div>
<div id="layout">
<input id="rPUZZLE" type="radio" name="type"/><label for="rPUZZLE">拼图布局</label>
<input id="rWATERFALL" type="radio" name="type" checked="checked"/><label for="rWATERFALL">瀑布布局</label>
<input id="rBARREL" type="radio" name="type"/><label for="rBARREL">木桶布局</label>
</div>
<div id="gutter">
设置间隔:
<input id="gutterX" type="number" min="0" placeholder="gutterX" value="0"/>
<input id="gutterY" type="number" min="0" placeholder="gutterY" value="0"/>
</div>
<div id="col">
列数:<input id="fixed" type="radio" name="column" checked="checked"/><label for="fixed">固定列数</label>
<input id="autoColumn" type="radio" name="column"/><label for="autoColumn">自动列数</label>
<br/>
<span id="columnText">列数:</span>
<input id="column" type="number" min="1" placeholder="Column" value="4"/>
</div>
<div id="height">
高度范围:
<input id="min" type="number" min="0" placeholder="min" value="250">~
<input id="max" type="number" min="0" placeholder="max" value="300"/>
</div>
<div id="fullScreen">
点击图片放大:
<input id="rNONE" type="radio" name="fullScreen" checked="checked"/><label for="rNONE">关闭</label>
<input id="rPAGE" type="radio" name="fullScreen"/><label for="rPAGE">窗口全屏</label>
<input id="rWINDOW" type="radio" name="fullScreen"/><label for="rWINDOW">全屏</label>
</div>
</div>
</div>
<script>
let A = document.getElementById("A");
let B = document.getElementById("B");
let w = document.getElementById("w");
let h = document.getElementById("h");
let gutter = document.getElementById("gutter");
let gutterX = document.getElementById("gutterX");
let gutterY = document.getElementById("gutterY");
let auto = document.getElementById("auto");
let lay = document.getElementById("layout");
let rPUZZLE = document.getElementById("rPUZZLE");
let rWATERFALL = document.getElementById("rWATERFALL");
let rBARREL = document.getElementById("rBARREL");
let col = document.getElementById("col");
let column = document.getElementById("column");
let height = document.getElementById("height");
let min = document.getElementById("min");
let max = document.getElementById("max");
let fullScreen = document.getElementById("fullScreen");
let rNONE = document.getElementById("rNONE");
let rPAGE = document.getElementById("rPAGE");
let rWINDOW = document.getElementById("rWINDOW");
let fixed = document.getElementById("fixed");
let autoColumn = document.getElementById("autoColumn");
let columnText = document.getElementById("columnText");
//随机图像
let types = [
'abstract', 'animals', 'business', 'cats',
'city', 'food', 'nightlife', 'fashion',
'people', 'nature', 'sports', 'technics',
'transport'
];
/** 相册操作部分 */
let obj = Album("album"); //构造Album对象
obj.setImage("", {
resizeUpdate: 250
}); //初始化
let layout = obj.getLayout();
gutter.style.display = layout != obj.LAYOUT.PUZZLE ? "block" : "none";
col.style.display = layout == obj.LAYOUT.WATERFALL ? "block" : "none";
height.style.display = layout == obj.LAYOUT.BARREL ? "block" : "none";
lay.addEventListener("click", function() {
if(rPUZZLE.checked && layout != obj.LAYOUT.PUZZLE) {
layout = obj.LAYOUT.PUZZLE;
obj.setLayout(layout);
} else if(rBARREL.checked && layout != obj.LAYOUT.BARREL) {
layout = obj.LAYOUT.BARREL;
obj.setLayout(layout);
} else if(rWATERFALL.checked && layout != obj.LAYOUT.WATERFALL) {
layout = obj.LAYOUT.WATERFALL;
obj.setLayout(layout);
}
gutter.style.display = layout != obj.LAYOUT.PUZZLE ? "block" : "none";
col.style.display = layout == obj.LAYOUT.WATERFALL ? "block" : "none";
height.style.display = layout == obj.LAYOUT.BARREL ? "block" : "none";
});
gutter.addEventListener("change", function() {
obj.setGutter(parseInt(gutterX.value), parseInt(gutterY.value));
});
let resizeUpdate = function() {
if(auto.checked) {
obj.resizeUpdate(250);
} else {
obj.resizeUpdate(-1);
}
};
let addImg = function() {
let type = Math.floor(types.length * Math.random());
if(A.checked) {
obj.addImage(`http://lorempixel.com/${w.value}/${h.value}/${types[type]}/Liming%20Jin/`)
.setAttribute("title", `LOREMPixel ${w.value}x${h.value}`);
} else if(B.checked) {
let R = Math.floor(239 * Math.random()) + 16;
let G = Math.floor(239 * Math.random()) + 16;
let B = Math.floor(239 * Math.random()) + 16;
let back = R.toString(16) + G.toString(16) + B.toString(16);
let fore = (255 - R).toString(16) + (255 - G).toString(16) + (255 - B).toString(16);
obj.addImage(`http://placehold.it/${w.value}x${h.value}/${back}/${fore}`)
.setAttribute("title", `Place Hold It ${w.value}x${h.value} ${back}/${fore}`);
}
};
let addRandom = function() {
w.value = Math.round(330 * Math.random()) + 470;
h.value = Math.round(330 * Math.random()) + 270;
addImg();
};
col.addEventListener("change", function() {
if(fixed.checked) {
obj.setWaterfallColumn(parseInt(column.value));
} else if(autoColumn.checked) {
obj.setWaterfallColumn(obj.WATERFALL_AUTO);
obj.setWaterfallAutoMinWidth(parseInt(column.value));
}
});
col.addEventListener("click", function (e) {
if(e.target == fixed) {
if(fixed.checked) {
columnText.innerHTML = "列数:";
column.value = 4;
}
} else if(e.target == autoColumn) {
if(autoColumn.checked) {
columnText.innerHTML = "最小列宽:";
column.value = 200;
}
}
});
height.addEventListener("change", function() {
obj.setBarrelHeight(parseInt(min.value), parseInt(max.value));
});
fullScreen.addEventListener("click", function() {
if(rNONE.checked) {
obj.setFullScreen(obj.FULL_SCREEN.NONE);
} else if(rPAGE.checked) {
obj.setFullScreen(obj.FULL_SCREEN.PAGE);
} else if(rWINDOW.checked) {
obj.setFullScreen(obj.FULL_SCREEN.WINDOW);
}
});
</script>
<script>
/**
* 操作面板拖动
*/
(function() {
//获取对象元素
var control = document.getElementById("control");
var title = document.getElementById("control-title");
//初始位置
control.style.left = 0;
control.style.top = (window.innerHeight - control.offsetHeight) + "px";
var draggingControl = false;
var start = [0, 0];
var position = [
control.style.left.substr(0, control.style.left.length - 2) - 0,
control.style.top.substr(0, control.style.top.length - 2) - 0
];
//绑定事件
title.addEventListener("mousedown", function(e) { //鼠标按下事件
start[0] = e.clientX - position[0];
start[1] = e.clientY - position[1];
draggingControl = true;
});
addEventListener("mouseup", function() { //鼠标抬起事件
draggingControl = false;
});
addEventListener("mousemove", function(e) { //鼠标移动事件
if(draggingControl) {
position[0] = e.clientX - start[0];
position[1] = e.clientY - start[1];
if(position[0] > window.innerWidth - control.offsetWidth) {
position[0] = window.innerWidth - control.offsetWidth;
}
if(position[0] < 0) {
position[0] = 0;
}
if(position[1] > window.innerHeight - control.offsetHeight) {
position[1] = window.innerHeight - control.offsetHeight;
}
if(position[1] < 0) {
position[1] = 0;
}
control.style.left = position[0] + "px";
control.style.top = position[1] + "px";
}
});
})();
</script>
</body>
</html>