css + js 弹出提示框

末蓝、 2022-03-06 15:48 643阅读 0赞

css :

  1. /*弹出框*/
  2. .alert {
  3. display: none;
  4. position: fixed;
  5. top: 50%;
  6. left: 50%;
  7. min-width: 300px;
  8. max-width: 600px;
  9. transform: translate(-50%,-50%);
  10. z-index: 99999;
  11. text-align: center;
  12. padding: 15px;
  13. border-radius: 3px;
  14. }
  15. .alert-success {
  16. color: #3c763d;
  17. background-color: #dff0d8;
  18. border-color: #d6e9c6;
  19. }
  20. .alert-info {
  21. color: #31708f;
  22. background-color: #d9edf7;
  23. border-color: #bce8f1;
  24. }
  25. .alert-warning {
  26. color: #8a6d3b;
  27. background-color: #fcf8e3;
  28. border-color: #faebcc;
  29. }
  30. .alert-danger {
  31. color: #a94442;
  32. background-color: #f2dede;
  33. border-color: #ebccd1;
  34. }

js:

  1. /**
  2. * 弹出式提示框,默认1.2秒自动消失
  3. * @param message 提示信息
  4. * @param style 提示样式,有alert-success、alert-danger、alert-warning、alert-info
  5. * @param time 消失时间
  6. */
  7. var prompt = function (message, style, time)
  8. {
  9. style = (style === undefined) ? 'alert-success' : style;
  10. time = (time === undefined) ? 1200 : time;
  11. $('<div>')
  12. .appendTo('body')
  13. .addClass('alert ' + style)
  14. .html(message)
  15. .show()
  16. .delay(time)
  17. .fadeOut();
  18. };
  19. // 成功提示
  20. var success_prompt = function(message, time)
  21. {
  22. prompt(message, 'alert-success', time);
  23. };
  24. // 失败提示
  25. var fail_prompt = function(message, time)
  26. {
  27. prompt(message, 'alert-danger', time);
  28. };
  29. // 提醒
  30. var warning_prompt = function(message, time)
  31. {
  32. prompt(message, 'alert-warning', time);
  33. };
  34. // 信息提示
  35. var info_prompt = function(message, time)
  36. {
  37. prompt(message, 'alert-info', time);
  38. };

发表评论

表情:
评论列表 (有 0 条评论,643人围观)

还没有评论,来说两句吧...

相关阅读