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.   
  11. </style>  
  12. <script>  
  13. //自定义弹框  
  14. function Toast(msg,duration){  
  15.     duration=isNaN(duration)?3000:duration;  
  16.     var m = document.createElement('div');  
  17.     m.innerHTML = msg;  
  18.     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;";  
  19.     document.body.appendChild(m);  
  20.     setTimeout(function() {  
  21.         var d = 0.5;  
  22.         m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';  
  23.         m.style.opacity = '0';  
  24.         setTimeout(function() { document.body.removeChild(m) }, d * 1000);  
  25.     }, duration);  
  26. }  
  27. </script>   
  28. </head>  
  29. <body>  
  30. <button onclick="Toast('您点击了弹框按钮!',2000);">Toast</button>  
  31. </body>  
  32. </html>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值