-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.html
138 lines (121 loc) · 4.04 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
<!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,chrome=1">
<title></title>
<style>
.editor { color:#00f; }
.editor > style { display: block; }
</style>
</head>
<body>
<pre class="editor" id="editor" contenteditable="true">
<style>
html {
height: 100vh;
}
body {
height: inherit;
background: #2e576b;
display: -ms-grid;
display: grid;
}
.container {
margin: auto;
}
.card {
position: relative;
width: 300px;
height: 350px;
background: #fff;
border-radius: 2px;
box-shadow: 0 2px 15px 3px rgba(0, 0, 0, 0.08);
overflow: hidden;
}
.card::after {
content: '';
display: block;
width: 100%;
height: 100%;
background: linear-gradient(to bottom, #0065a8, rgba(221, 238, 255, 0.4) 46%, rgba(255, 255, 255, 0.5));
}
.wave {
position: absolute;
top: 3%;
left: 50%;
width: 400px;
height: 400px;
margin-top: -200px;
margin-left: -200px;
background: #0af;
border-radius: 40%;
opacity: .4;
animation: shift 3s infinite linear;
}
.wave.w2 {
background: yellow;
opacity: .1;
animation: shift 7s infinite linear;
}
.wave.w3 {
animation: shift 5s infinite linear;
background: crimson;
opacity: 0.1;
}
@-webkit-keyframes shift {
from {
transform: rotate(360deg);
}
}
@keyframes shift {
from {
transform: rotate(360deg);
}
}
</style>
<div class="container">
<div class="card">
<div class="wave w1"></div>
<div class="wave w2"></div>
<div class="wave w3"></div>
</div>
</div>
</pre>
<button class="btn btn-preview" id="preview" type="button">预览</button>
<script>
// 按钮
var button = document.getElementById('preview');
// 编辑区域
var editor = document.getElementById('editor');
// 准备一个iframe
var iframe = document.createElement('iframe');
iframe.style.position = 'fixed';
iframe.style.top = "10%";
iframe.style.left = "10%";
iframe.style.width = "80%";
iframe.style.height = "80%";
iframe.style.display = "none";
// 点击事件
button.addEventListener('click', function (e) {
e.stopPropagation();
// 取得编辑区域内容并转化为blob
var blob = new Blob([editor.innerText], {
type: 'text/html'
});
// 转成url对象设置给iframe 并显示iframe
iframe.src = URL.createObjectURL(blob);
iframe.style.display = "block";
document.body.appendChild(iframe);
});
// 其他地方点击时关闭预览
document.body.addEventListener('click', function (e) {
if(iframe.style.display == "none") return;
// 隐藏并移除
iframe.style.display = "none";
document.body.removeChild(iframe);
});
</script>
</body>
</html>