js寫一個提示框
阿新 • • 發佈:2021-01-11
js部分
//提示框——封裝函式
function msgS(data, time) {
let msg_c = document.createElement('div');
msg_c.id = "msg_c"
let alertForm = document.createElement('div');
alertForm.id = "successMsg";
alertForm.innerHTML = data;
msg_c.appendChild(alertForm);
document. getElementsByTagName("body")[0].appendChild(msg_c);
if (time) {
setTimeout(function () {
msg_c.style.display = "none";
}, time)
} else {
setTimeout(function () {
msg_c.style.display = "none";
}, 2000)
}
};
//使用
msgS('操作成功',3000);//引數1:提示內容;引數二:關閉時間(不填預設2秒)
css樣式
/* 提示框 */
html,
body {
width: 100%;
height: 100%;
}
#msg_c{
position: fixed;
top: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
z-index: 999999;
}
#successMsg {
background: #FFFFFF;
box-shadow: 0px 0px 16px 0px rgba(148, 148, 148, 0.36);
border-radius: 4px;
line-height: 80px;
padding-left: 35px;
padding-right: 35px;
font-size: 18px;
font-family: Microsoft YaHei;
font-weight: 400;
color: #117BED;
z-index: 9999;
}