当前位置: 代码迷 >> 综合 >> 自定义Toast函数
  详细解决方案

自定义Toast函数

热度:47   发布时间:2023-09-13 11:29:11.0
功能需求:有的toast不好用或者不符合产品样式,可以自定义一个toast函数,里面样式可以自己定义
/* Toast自定义函数 */
function Toast(msg, duration) {duration = isNaN(duration) ? 1500 : duration;var m = document.createelement('div');m.innerHTML = msg; //width:34%m.style.cssText = "width: 34%;min-width: 90px;height: auto;color: #fff;line-height: auto;text-align: center;border-radius: 5px;padding:10px;position: fixed;top: 40%;left: 33%;z-index: 999999;background: #696969;font-size: 14px;";document.body.appendChild(m);setTimeout(function () {var d = 0.5;m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';m.style.opacity = '0';setTimeout(function () {document.body.removeChild(m)}, d * 1000);}, duration);
}

例如:直接使用:Toast(‘请输入手机号’)