.dialog {
      width: 150px;
      height: 50px;
      line-height: 50px;
      font-weight: bold;
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%,-50%);
      border-radius: 5px;
      background-color: pink;
      text-align: center;
      color: #000;
}

js代码区域:

Dialog = function (obj) {
    this.div = document.createElement('div')
    this.div.innerText = obj.title
    this.div.classList.add('dialog')
    document.body.appendChild(this.div)
    this.on = function (type, callback) {
      console.log(this)
      let dialog = document.getElementsByClassName('dialog')
      if (type == 'show') {
        this.div.style.display = 'block'
        callback()
      } else if (type == 'close') {
        this.div.style.display = 'none'
        callback()
      }
    }
  }

实例化一下,即可
let dialog = new Dialog({title: '这是标题'})

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄