myTips.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. function showTips(type,txt){
  2. var _html = "";
  3. if (type == "warn") {
  4. _html += '<div class="p-mytips align-center warn">';
  5. _html += '<span class="ic zicon-warning"></span>';
  6. }
  7. if (type == "error") {
  8. _html += '<div class="p-mytips align-center error">';
  9. _html += '<span class="ic zicon-error"></span>';
  10. }
  11. _html += '<span class="txt">'+txt+'</span>';
  12. _html += '</div>';
  13. //必须先将_html添加到body,再设置Css样式
  14. $("body").append(_html);
  15. //生成Css
  16. GenerateCss();
  17. GenerateTipsAni();
  18. }
  19. function GenerateTipsAni() {
  20. $(".p-mytips").removeClass("animation_slideInDown animation_slideOutUp").addClass("animation_slideInDown");
  21. setTimeout(()=>{
  22. $(".p-mytips").removeClass("animation_slideInDown").addClass("animation_slideOutUp animate__delay-1s");
  23. },1000)
  24. setTimeout(()=>{
  25. $(".p-mytips").remove();
  26. },10000)
  27. }
  28. function GenerateCss(){
  29. $(".p-mytips").css({
  30. position: 'fixed',
  31. top: '10vh',
  32. left: '50%',
  33. transform: 'translateX(-50%)',
  34. 'min-width': '380px',
  35. padding: '16px',
  36. 'z-index': '100',
  37. 'border-radius': '4px',
  38. });
  39. $(".p-mytips .txt").css({
  40. 'font-size': '14px'
  41. });
  42. $(".p-mytips .ic").css({
  43. 'margin-right': '10px',
  44. 'font-size': '16px'
  45. });
  46. $(".p-mytips.warn").css({
  47. 'background-color':'#fff8e6',
  48. 'border-color':'#fff1cc',
  49. 'color':'#ffba00'
  50. });
  51. $(".p-mytips.error").css({
  52. 'background-color':'#ffeded',
  53. 'border-color':'#ffdbdb',
  54. 'color':'#ff4949'
  55. });
  56. }