-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
370 lines (304 loc) · 7.88 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
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" name="viewport" content="width=device-width,initial-scale=1.0">
<title>带壳截图工具</title>
<style>
body
{
height:100%;
}
h1
{
text-align: center;
margin:0 auto;
padding:0;
}
.left-bar
{
float:left;
width:50%;
overflow:visible;
}
.right-bar
{
width:50%;
float:right;
}
.mobile-phone
{
position:relative;
margin:0 auto;
background-image: url(iphone6_white.png);
width:410px;
height:835px;
margin-bottom:30px;
}
.buttons
{
margin-top:50px;
}
.shoot-photo
{
width:88%;
height:77%;
background:url();
background-size:100%;
background-repeat: no-repeat;
position:absolute;
top:12%;
left:6%;
}
.mobile-phone-iphone5
{
background-image: url(iphone5_black.png);
width:410px;
height:864px;
}
.shoot-photo-iphone5
{
height:74%;
}
.create-photo,.download,.change-phone
{
box-sizing: content-box;
/*button在display为block之后,chrome默认为borderbox了*/
display: block;
text-align: center;
width:200px;
padding:20px;
margin:0 auto;
border-radius: 10px;
color: #888;
background: #fafafa;
border: 1px solid #ddd;
margin-bottom: 30px;
cursor:pointer;
font-size: 22px;
/*测试放大的效果 */
/*transform:translateY(100px);*/
}
.wrap
{
text-align: center;
font-size: 22px;
margin:0 auto;
width:200px;
padding:20px;
color: #888;
background: #fafafa;
border: 1px solid #ddd;
border-radius: 10px;
position:relative;
overflow:hidden;
cursor:pointer;
z-index:1;
margin-bottom: 20px;
}
.wrap:hover,.create-photo:hover,.download:hover,.change-phone:hover
{
color: #444;
background: #eee;
border-color: #ccc;
}
/* .dropdown-content
{
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 2;
}
.show-content
{
display: block;
}*/
.dropdown-content a
{
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/*
.change-phone:hover .dropdown-content
{
display:block;
}
.change-phone:focus .dropdown-content
{
display:block;
}*/
.upload-photo
{
opacity:0;
position:absolute;
font-size:22px;
top:0;
right:0;
cursor:pointer;
}
.result-photo
{
margin:0 auto;
max-width:410px;
height:835px;
}
a
{
text-decoration: none;
}
@media only screen and (max-width: 900px) {
.left-bar,.right-bar
{
width:100%;
}
.right-bar
{
padding-top:30px;
border-top:1px solid black;
}
}
@media only screen and (max-width: 450px) {
.mobile-phone
{
width:90%;
height:0;
padding-bottom:184%;
background-size: contain;
background-repeat: no-repeat;
}
.result-photo
{
width:90%;
height:0;
padding-bottom:184%;
}
.result-photo img
{
width:100%;
height:auto;
padding-bottom:184%;
}
canvas
{
width:100%;
height:auto;
}
}
</style>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery
/jquery-1.4.min.js"></script>
<!-- <script type="text/javascript" src="http://html2canvas.hertzen.com/build/html2canvas.js"></script> -->
<!-- <script type="text/javascript" src="../photo/html2canvas0.4.1.js"></script>
-->
<script type="text/javascript" src="../photo/html2canvas0.5.1.js"></script>
<!-- <script type="text/javascript" src="canvas2image.js"></script> -->
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$(".shoot-photo")
.css('background-image', 'url('+e.target.result+')');
};
reader.readAsDataURL(input.files[0]);
}
}
function drawAll()
{
var useWidth = $("#mobile-phone").width();
var useHeight = $("#mobile-phone").height() || $("#mobile-phone").innerHeight();
//html2canvas0.4.1不支持caontain的背景
//https://github.com/niklasvh/html2canvas/issues/265
//通过这个issue修改了350行,可以支持contain的背景了
//现在使用0.5.1不存在这个问题
//为了提高分辨率 按照http://www.jianshu.com/p/96ce8a0df559
//的做法修改了604line
// $(".mobile-phone").addClass('x2');
html2canvas($("#mobile-phone"),
{
// width: useWidth*2,
// height: useHeight*2,
onrendered:function(canvas)
{
//适应移动端,放弃描绘canvas,直接转换成img
/*
$(".result-photo").html(canvas);
// $(".result-photo").append(canvas);
$("canvas").attr('id', 'canvas');
var item = $(".download");
// console.log(item);
item.attr('href', canvas.toDataURL("image/png").replace("image/png","image/octet-stream"));
item.attr('download',"带壳截图.png");
*/
//生成img
var dataUrl = canvas.toDataURL();
var newImg = document.createElement("img");
newImg.src = dataUrl;
$(".result-photo").html("");
$(".result-photo").html(newImg);
}
})
}
function showPhone()
{
console.log("display is block!");
var phoneSelections = $(".dropdown-content");
phoneSelections.addClass("show-content");
}
function changePhone(phoneName)
{
var mobilePhone = $("#mobile-phone");
var shootPhoto = $("#shoot-photo");
mobilePhone.removeClass();
mobilePhone.addClass("mobile-phone");
shootPhoto.removeClass();
shootPhoto.addClass("shoot-photo")
if(phoneName != "iphone6")
{
mobilePhone.addClass("mobile-phone-"+phoneName);
shootPhoto.addClass("shoot-photo-"+phoneName);
}
console.log(phoneName+"change finished!");
var phoneSelections = $(".dropdown-content");
// phoneSelections.removeClass("show-content");
// console.log("display is none!");
}
$(document).ready(function() {
$(".create-photo").click(drawAll);
// $(".change-phone").click(showPhone);
});
</script>
</head>
<body>
<h1>张小船的截图制造机哈哈哈</h1>
<hr>
<div class="left-bar">
<div class="mobile-phone" id="mobile-phone">
<div class="shoot-photo " id="shoot-photo">
<!-- <img src="shoot4.jpg" alt="截图"> -->
</div>
</div>
<button class="change-phone" onclick="changePhone('iphone6')">iphone6</button>
<button class="change-phone" onclick="changePhone('iphone5')">iphone5</button>
<div class="wrap">
上传截图!!!
<input class="upload-photo" type='file' onchange="readURL(this);" />
</div>
<button class="create-photo">生成带壳截图</button>
</div>
</div>
<div class="right-bar">
<div class="result-photo">
</div>
<!-- <div class="buttons">
<button class="download">下载截图</button>
<a class="download" >下载截图</a>
</div> -->
</div>
</body>
</html>