toast.js 718 B

1234567891011121314151617
  1. function Toast(msg, duration) {
  2. duration = isNaN(duration) ? 3000 : duration;
  3. var m = document.createElement('div');
  4. m.innerHTML = msg;
  5. m.style.cssText =
  6. "max-width:60%;min-width: 150px;padding:0 14px;height:auto;color: rgb(255, 255, 255);line-height: 40px;text-align: center;border-radius: 4px;position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);z-index: 999999;background: rgba(0, 0, 0,.7);font-size: 16px;";
  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. }