当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery实现消息弹出框效果

jQuery实现消息弹出框效果

2020年03月09日  | 移动技术网IT编程  | 我要评论

本文实例为大家分享了jquery消息弹出框的具体代码,供大家参考,具体内容如下

效果图

实现代码

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <!-- bootcdn提供了很多如jquery、chart.js、ecarts.js等等,bootcdn官网地址:http://www.bootcdn.cn/-->
  <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
 
  <style type="text/css">
    .showmessage {
      padding: 5px 10px;
      border-radius: 5px;
      position: fixed;
      top: 45%;
      left: 45%;
      color: #ffffff;
    }
 
    .showmessagesuccess {
      background-color: #00b7ee;
    }
 
    .showmessageerror {
      background-color: #ff0000;
    }
  </style>
 
  <script type="text/javascript">
    $(function () {
 
      $("#refresh1").click(function () {
        showmessage("注册成功",1);
      });
 
      $("#refresh2").click(function () {
        showmessage("您的网络已断开!",0);
      });
    });
 
    /**
     * 弹出消息提示框,采用浏览器布局,位于整个页面中央,默认显示3秒
     * 后面的消息会覆盖原来的消息
     * @param message:待显示的消息
     * @param type:消息类型,0:错误消息,1:成功消息
     */
    function showmessage(message, type) {
      let messagejq = $("<div class='showmessage'>" + message + "</div>");
      if (type == 0) {
        messagejq.addclass("showmessageerror");
      } else if (type == 1) {
        messagejq.addclass("showmessagesuccess");
      }
      /**先将原始隐藏,然后添加到页面,最后以600秒的速度下拉显示出来*/
      messagejq.hide().appendto("body").slidedown(600);
      /**3秒之后自动删除生成的元素*/
      window.settimeout(function () {
        messagejq.remove();
      }, 3000);
    }
 
  </script>
</head>
<body>
<button id="refresh1">正确消息</button>
<button id="refresh2">正确消息</button>
</body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网