JavaScript 代码如下:
1 < script > 2 var toast = function (msg, duration) { 3 duration = isNaN(duration) ? 3000 : duration; 4 var m = document.createElement('div'); 5 m.innerHTML = msg; 6 m.style.cssText = "width: 60%;min-width: 150px;opacity: 0.7;height: 30px;color: rgb(255, 255, 255);line-height: 30px;text-align: center;border-radius: 5px;position: fixed;top: 40%;left: 20%;z-index: 999999;background: rgb(0, 0, 0);font-size: 12px;"; 7 document.body.appendChild(m); 8 setTimeout(function () { 9 var d = 0.5; 10 m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in'; 11 m.style.opacity = '0'; 12 setTimeout(function () { 13 document.body.removeChild(m) 14 }, d * 1000); 15 }, duration); 16 } 17 </script>
文章摘自: https://blog.csdn.net/zhaodecang/article/details/78029831