본문 바로가기
Developer/HTML & JSP & CSS

[HTML] HTML2CANVAS

by 순수한소년 2020. 3. 26.
728x90
반응형
html2canvas_sample.html
0.00MB
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
<!DOCTYPE html>
 
<html lang="en">
 
<head>
 
<title>CSS Template</title>
 
<meta charset="utf-8">
 
<meta name="viewport" content="width=device-width, initial-scale=1">
 
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
 
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
 
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.min.js"></script>
 
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js"></script> 
 
<style>
 
{
 
  box-sizing: border-box;
 
}
 
 
body {
 
  font-family: Arial, Helvetica, sans-serif;
 
}
 
 
/* Style the header */
 
header {
 
  background-color: #666;
 
  padding: 30px;
 
  text-align: center;
 
  font-size: 35px;
 
  color: white;
 
}
 
 
/* Create two columns/boxes that floats next to each other */
 
nav {
 
  float: left;
 
  width: 30%;
 
  height: 300px; /* only for demonstration, should be removed */
 
  background: #ccc;
 
  padding: 20px;
 
}
 
 
/* Style the list inside the menu */
 
nav ul {
 
  list-style-type: none;
 
  padding: 0;
 
}
 
 
article {
 
  float: left;
 
  padding: 20px;
 
  width: 70%;
 
  background-color: #f1f1f1;
 
  height: 300px; /* only for demonstration, should be removed */
 
}
 
 
/* Clear floats after the columns */
 
section:after {
 
  content: "";
 
  display: table;
 
  clear: both;
 
}
 
 
/* Style the footer */
 
footer {
 
  background-color: #777;
 
  padding: 10px;
 
  text-align: center;
 
  color: white;
 
}
 
 
/* Responsive layout - makes the two columns/boxes stack on top of each other instead of next to each other, on small screens */
 
@media (max-width: 600px) {
 
  nav, article {
 
    width: 100%;
 
    height: auto;
 
  }
 
}
 
</style>
 
</head>
 
<body>
 
<input type="button" value="캡쳐" />
 
 
<h2>CSS Layout Float</h2>
 
<p>In this example, we have created a header, two columns/boxes and a footer. On smaller screens, the columns will stack on top of each other.</p>
 
<p>Resize the browser window to see the responsive effect (you will learn more about this in our next chapter - HTML Responsive.)</p>
 
 
<header>
 
  <h2>Cities</h2>
 
</header>
 
 
<section>
 
  <nav>
 
    <input type="button" value="캡쳐" />
 
    <ul>
 
      <li><a href="#">London</a></li>
 
      <li><a href="#">Paris</a></li>
 
      <li><a href="#">Tokyo</a></li>
 
    </ul>
 
  </nav>
 
 
  <article>
 
    <h1>London</h1>
 
    <p>London is the capital city of England. It is the most populous city in the  United Kingdom, with a metropolitan area of over 13 million inhabitants.</p>
 
    <p>Standing on the River Thames, London has been a major settlement for two millennia, its history going back to its founding by the Romans, who named it Londinium.</p>
 
    <input type="button" value="캡쳐" />
 
  </article>
 
</section>
 
 
<footer>
 
  <p>Footer</p>
 
</footer>
 
 
<a id="target" style="display: none"></a>
 
<script>
 
 
$(":button").on('click'function(e) {
 
  // html2canvas(e.target.parentElement).then(function(canvas) {
 
  //   document.body.appendChild(canvas)
 
  // });
 
 
  // html2canvas(e.target.parentElement).then(function(canvas) {
 
  //   $('body').append('<img src="' + canvas.toDataURL("image/jpeg") + '"/>');
 
  // });
 
 
  html2canvas(e.target.parentElement).then(function(canvas) {
 
    if (navigator.msSaveBlob) {
 
      var blob = canvas.msToBlob(); 
 
      return navigator.msSaveBlob(blob, '파일명.jpg'); 
 
    } else { 
 
      var el = document.getElementById("target");
 
      el.href = canvas.toDataURL("image/jpeg");
 
      el.download = '파일명.jpg';
 
      el.click();
 
    }
 
  });
 
 
});
 
 
</script>
 
</body>
 
</html>
cs
728x90
반응형