天天看点

html5+css3实现手机toast提示

  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  5. <title>自定义Toast,类似于android的Toast</title>  
  6. <style>  
  7. body {  
  8.     font-family: 'Lucida Grande', 'Helvetica', sans-serif;  
  9. }  
  10. </style>  
  11. <script>  
  12. //自定义弹框  
  13. function Toast(msg,duration){  
  14.     duration=isNaN(duration)?3000:duration;  
  15.     var m = document.createElement('div');  
  16.     m.innerHTML = msg;  
  17.     m.style.cssText="width:60%; min-width:150px; background:#000; opacity:0.5; height:40px; color:#fff; line-height:40px; text-align:center; border-radius:5px; position:fixed; top:40%; left:20%; z-index:999999; font-weight:bold;";  
  18.     document.body.appendChild(m);  
  19.     setTimeout(function() {  
  20.         var d = 0.5;  
  21.         m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';  
  22.         m.style.opacity = '0';  
  23.         setTimeout(function() { document.body.removeChild(m) }, d * 1000);  
  24.     }, duration);  
  25. </script>   
  26. </head>  
  27. <body>  
  28. <button onclick="Toast('您点击了弹框按钮!',2000);">Toast</button>  
  29. </body>  
  30. </html>  

继续阅读