zoukankan      html  css  js  c++  java
  • toast提示 封装

    直接上代码  拿走不送!

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>toast</title>
     6     <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
     7     <style>
     8         .toast {
     9             position: fixed;
    10             top: 18%;
    11             left: 50%;
    12             transform: translateX(-50%);
    13             padding: 10px 20px;
    14             border-radius: 6px;
    15             color: #fff;
    16             font-size: 14px;
    17             min-width: 250px;
    18             text-align: center;
    19             display: none;
    20             z-index: 10000;
    21             border:solid 1px #fff;
    22         }
    23 
    24         .succ {
    25             background: rgb(78, 164, 78);
    26             display: block;
    27         }
    28 
    29         .fail {
    30             background: rgba(230, 0, 0, 0.6);
    31             display: block;
    32         }
    33     </style>
    34 </head>
    35 <body>
    36     <button type="button" id="btn">
    37         点击
    38     </button>
    39      <div class="toast " style="top:8%; "></div>
    40 </body>
    41 <script type="text/javascript">
    42     $('#btn').on("click",function(){
    43         toast('事件成功', 'succ',1);
    44     })
    45     //toast
    46     function toast(content, sName, fn) {
    47         $('.toast').addClass(sName);
    48         $('.toast').html(content);
    49         setTimeout(() => {
    50             $('.toast').removeClass(sName);
    51             $('.toast').html('');
    52             if (fn) {
    53                 console.log(1)
    54                 toast('事件失败', 'fail');
    55             }
    56         }, 2000);
    57     }
    58 </script>
    59 </html>
  • 相关阅读:
    机器人
    仙岛求药(一)
    YZM 二分查找
    珠心算测验升级版
    博客正在施工
    【其他】16年12月博客阅读索引^_^
    博客有新家了!
    POJ No.3617【B008】
    POJ No.2386【B007】
    【刷题记录】部分和问题
  • 原文地址:https://www.cnblogs.com/xuwupiaomiao/p/13498520.html
Copyright © 2011-2022 走看看