This repository has been archived by the owner on Dec 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 357
/
demo.html
59 lines (59 loc) · 1.57 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>html2canvas demo</title>
<style>
#card{
width: 300px;
margin: 0 auto;
border: 1px solid rebeccapurple;
border-radius: 10px;
background-color: yellowgreen;
text-align: center;
}
h1{
color: red;
}
.test{
margin-top: 10px;
text-align: center;
}
</style>
</head>
<body>
<div id="card">
<h1>Dunizb</h1>
<h3><a href="http://dunizb.com">http://dunizb.com</a></h3>
<spna>这世间唯有梦想和好姑娘不可辜负!</spna>
</div>
<div class="test">
<button onclick="saveImage()">保存为图片</button>
<button onclick="saveImage(150,150)">保存为图片150X150</button>
</div>
</body>
<script src="html2canvas.min.js"></script>
<script>
function saveImage(x, y) {
if (!x && !y) {
console.log(1)
html2canvas(document.getElementById('card'), {
onrendered: function(canvas) {
document.body.appendChild(canvas);
}
});
} else {
console.log(x, y)
html2canvas(document.getElementById('card'), {
onrendered: function(canvas) {
document.body.appendChild(canvas);
},
width: x,
height: y
});
}
}
</script>
</html>