1 Star 2 Fork 0

范德萨/HTMLCourse

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Toast.js 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
范德萨 提交于 2023-02-21 21:19 +08:00 . update
class Toast {
static _toast = []
static timer = null
static show(message, duration) {
this._toast.push({
msg: message,
dur: duration ? duration : 2000
})
this.#check()
}
static #check() {
if (this._toast.length == 0) return;
if (this.timer == null) {
const t = this._toast.shift()
let d = document.createElement('div')
d.innerHTML = `<p style="border-radius: 30px;padding: 8px 16px;background-color: #dd000080;color: white; pointer-events: auto;">${t.msg}</p>`
d.style = 'position: fixed;margin: auto;font-size: 16px;left: 0;right: 0;bottom: 40px;z-index: 100;align-items: center;justify-content: center;display: none;pointer-events: none'
document.body.appendChild(d)
$(d).fadeIn(300)
this.timer = setTimeout(() => {
$(d).fadeOut(300, () => {
document.body.removeChild(d)
this.timer = null
this.#check()
})
}, t.dur + 300)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ffffffds/htmlcourse.git
git@gitee.com:ffffffds/htmlcourse.git
ffffffds
htmlcourse
HTMLCourse
master

搜索帮助