给主题加一个右侧气泡式提醒

  • ~2.93K 字
  • 次阅读
  • 条评论
  1. 1. 源码
  2. 2. 用法

简单的稀烂的小玩意

本文已过时,请参见->这里<-

源码

js:

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
// 右侧气泡式提醒,写的极烂233
var bubbleNum = 0;
function bubbleNoticer(text, type, time = 1500) {
bubbleNum = setBubbleNoticer(text, type, time);
function setBubbleNoticer(text, type, time) {
if (type == "normal") {
var bg = "#cfe2ff" ;
var iconbg = "#084298" ;
var icon = "\\f021";
} else if (type == "problem") {
var bg = "#fff3cd";
var iconbg = "#664d03";
var icon = "\\f071";
} else if (type == "err") {
var bg = "#f8d7da";
var iconbg = "#842029";
var icon = "\\f12a";
} else if (type == "ok") {
var bg = "#d1e7dd";
var iconbg = "#0f5132";
var icon = "\\f00c";
} else {
var bg = type;
var iconbg = "#084298" ;
var icon = "\\f021";
}
var noticer = document.createElement("div");
var c = document.getElementsByClassName("bubbleNoticer").length;
if (c == 0) {
bubbleNum = 0;
} else {
bubbleNum = bubbleNum+1;
}
noticer.setAttribute("class", "bubbleNoticer " + type);
noticer.style.backgroundColor = bg;
noticer.style.top = 60 + bubbleNum * 40 + "px";
var node = document.createTextNode(text);
noticer.appendChild(node);
var page = document.getElementById("kratos-wrapper");
page.appendChild(noticer);
document.styleSheets[0].insertRule('.' + type + '::before{color: '+ iconbg +';content: "'+ icon +'";}',0)
setTimeout(() => {
remove();
}, time);
function remove() {
noticer.style.top = "-40px";
setTimeout(() => {
page.removeChild(noticer);
}, 500);
}
return bubbleNum;
}
}

css:

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
@keyframes slideInRight {
from {
right: -230px;
}
to {
right: 0;
}
}
.bubbleNoticer {
color: #666;
font-weight: bold;
position: fixed;
right: 0;
padding: 10px;
width: 150px;
min-height: 15px;
line-height: 15px;
font-size: 15px;
z-index: 1;
opacity: 0.8;
border-top-left-radius: 20px;
border-bottom-left-radius: 20px;
animation-duration: 0.5s;
animation-name: slideInRight;
transition: top .5s;
word-break: break-all;
&::before {
font: 100%/1 FontAwesome;
margin-right: 10px;
}
}

用法

1
bubbleNoticer('text','type','time')

参数:

  • text: 显示的文字
  • type: 可用参数:normalerrproblemok
    其实就是改个颜色,所以也可以填颜色码:#ff1
  • time: 气泡持续时间(ms),默认:1500

使用实例:

1
<button onclick="bubbleNoticer('呜呜呜,为什么点我!','normal')">啊,不要点我!QAQ</button>




分享这一刻
让朋友们也来瞅瞅!