-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathexample.html
172 lines (169 loc) · 4.82 KB
/
example.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
margin: 0;
}
#test {
margin: 0 auto;
width: 1000px;
height: 120vh;
display: flex;
justify-content: center;
align-items: center;
}
#test button {
margin: 0 20px;
}
.coco-btn {
font-size: 14px;
text-decoration: none;
padding: 6px 20px;
white-space: nowrap;
border-radius: 5px;
font-weight: 500;
display: inline-block;
cursor: pointer;
border: 0;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
line-height: normal;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.coco-btn.cancel {
margin-right: 10px;
color: #525456;
background-color: transparent;
font-weight: 500;
transition: all 0.06s ease-out;
}
.coco-btn,
.coco-btn span,
.coco-loading {
position: relative;
}
.coco-btn.ok {
background-color: #0077ff;
color: #fefefe;
}
.coco-btn.ok::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: inherit;
transition: all 0.12s ease-out;
background-color: transparent;
}
.coco-btn.ok:hover::before {
background-color: rgba(255, 255, 255, 0.08);
}
.coco-btn.ok:active::before {
transition: all 80ms ease-out;
background-color: rgba(0, 0, 0, 0.2);
}
body {
background-color: #fff;
}
.dark body {
background-color: #111;
}
.github {
font-weight: 600;
text-align: center;
margin-top: 100px;
}
</style>
</head>
<body>
<div class="github">
<a
href="http://github.com/TheWindRises-2/coco-message"
target="_blank"
rel="noopener noreferrer"
>github</a
>
</div>
<div id="test">
<button class="coco-btn ok" onclick="changeText(0)">信息</button>
<button class="coco-btn ok" onclick="changeText(1)">成功</button>
<button class="coco-btn ok" onclick="changeText(2)">警告</button>
<button class="coco-btn ok" onclick="changeText(3)">错误</button>
<button class="coco-btn ok" onclick="changeText(4)">加载</button>
<button class="coco-btn ok" onclick="changeText(5)">closeAll</button>
<button class="coco-btn ok" onclick="changeMode()" id="mode">dark</button>
</div>
<script src="./coco-message.min.js"></script>
<script>
cocoMessage.config({
duration: 10000,
});
let theme = localStorage.theme || "light";
let mode = document.querySelector("#mode");
if (
theme === "dark" ||
(!("theme" in localStorage) &&
window.matchMedia("(prefers-color-scheme: dark)").matches)
) {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
mode.innerHTML = theme;
function changeMode() {
if (theme === "light") {
theme = "dark";
localStorage.theme = "dark";
document.documentElement.classList.add("dark");
} else {
theme = "light";
localStorage.theme = "light";
document.documentElement.classList.remove("dark");
}
mode.innerHTML = theme;
}
function changeText(num) {
switch (num) {
case 0:
cocoMessage.info(1500, "这是一条消息", () => {
console.log("close");
});
break;
case 1:
let div1 = document.createElement("div");
div1.innerText = "这是一条成功的消息";
cocoMessage.success(div1);
break;
case 2:
cocoMessage.warning("需要手动关闭消息", 0);
break;
case 3:
cocoMessage.error("这是一条错误的消息", 3000);
break;
case 4:
let closeMsg = cocoMessage.loading(true);
setTimeout(() => {
closeMsg();
cocoMessage.success("加载成功");
}, 4000);
break;
case 5:
cocoMessage.destroyAll();
break;
default:
break;
}
}
</script>
</body>
</html>