<div id='toast'></div>
.toast-container {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 80%;
height: auto;
padding: 20px;
background-color: #333;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, .4);
text-align: center;
font-size: 14px;
transition: opacity .3s;
color: #fff;
display: none;
}
提示框方法
Toast(str, options = {}) {
let {
time,
html
} = options;
if (!time) time = 1200;
const toastEl = document.getElementById('toast');
const className = 'toast-container';
toastEl.className = className;
if (html) {
toastEl.innerHTML = html+str;
} else {
if (toastEl.textContent) {
toastEl.textContent = str;
} else {
toastEl.innerText = str;
}
}
toastEl.style='display: block'
setTimeout(() => {
toastEl.style='display: none'
}, time);
},
调用
time 显示时间
html 看情况自己修改,一般情况下传空
this.Toast('提示语', {
time: "1000",
html: ""
})