jqAlert.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* * author:wqq date:2020-03-09 */
  2. (function($) {
  3. $.extend ({
  4. jqAlert: function(option) {
  5. let _this = this;
  6. var settings = {
  7. type: 'info', //info,success,warning,error
  8. content: '提示内容',
  9. autoClose: true
  10. };
  11. var $dom = $ ('.my_alert-wrapper');
  12. if ($dom.length === 0) {
  13. $ (document.body).append ('<div class="my_alert-wrapper"></div>');
  14. }
  15. $dom = $ ('.my_alert-wrapper');
  16. $.extend (settings, option);
  17. let box = $ ('<div class="my_alertBox" animation=""></div>');
  18. box.addClass ('my_alertBox--' + settings.type);
  19. let typeIcon = $ ('<i class="icon-chenggong iconfont share-i"></i>');
  20. typeIcon.addClass ('icon-alert-' + settings.type);
  21. let contentBox = $ ('<div class="my_alert-content"></div>');
  22. contentBox.text (settings.content);
  23. let closeIcon = $ ('<i class="my_alert-closebtn iconfont icon-biaoqing share-i"></i>');
  24. box.append (typeIcon).append (contentBox).append (closeIcon);
  25. $dom.append (box);
  26. if (settings.autoClose === true) {
  27. setTimeout (function() {
  28. box.remove ();
  29. }, 3 * 1000);
  30. }
  31. closeIcon.on ('click', function() {
  32. box.remove ();
  33. });
  34. }
  35. });
  36. }) (jQuery);