注:样式文件在底部

showToast

showToast.gifshowToast1.gif

  1. /*提示弹窗
  2. *@method showToast
  3. *@for
  4. *@param{对象}options: otpions.icon;options.title;options.duration;
  5. *@return {void}
  6. */
  7. function showToast(options) {
  8. options = options ? options : {};
  9. options.icon = options.icon != 'none';
  10. options.title = options.title ? options.title : '';
  11. options.duration = options.duration ? options.duration : 1500;
  12. var toast = '<div class="toast"><div class="toast-wrapper">'
  13. + (options.icon ? '<div class="toast-icon"><img src="../imgs/i_success.png" alt="" class="img"></div>' : '') +
  14. '<div class="toast-content">' + options.title + '</div></div></div>';
  15. $('body').append(toast);
  16. setTimeout(() => {
  17. $('.toast').fadeOut(500).remove();
  18. }, options.duration);
  19. }
  20. // 使用
  21. showToast({title: '登录成功!'})

showLoading、hideLoading

showLoading.gif

  1. /*提示弹窗
  2. *@method showLoading
  3. *@for
  4. *@param{对象}options: otpions.icon;options.title;options.duration;
  5. *@return {void}
  6. */
  7. function showLoading(options) {
  8. options = options ? options : {};
  9. options.icon = options.icon != 'none';
  10. options.title = options.title ? options.title : '加载中...';
  11. options.duration = options.duration ? options.duration : 1500;
  12. var loading = '<div class="loading"><div class="loading-wrapper">'
  13. + (options.icon ? '<div class="loading-icon"><img src="../imgs/loading.gif" alt="" class="img"></div>' : '') +
  14. '<div class="loading-content">' + options.title + '</div></div></div>';
  15. $('body').append(loading);
  16. };
  17. function hideLoading() {
  18. $('.loading').fadeOut(500).remove();
  19. };
  20. // 使用
  21. showLoading({title: '加载中...'});
  22. $.ajax({
  23. ...,
  24. complete: function() {
  25. hideLoading();
  26. }
  27. })

showModel

showModel.gif

  1. /*提示弹窗
  2. *@method showModel
  3. *@for
  4. *@param{对象}options: otpions.icon;options.content;options.showCancel;options.onCancel;options.confirmText;options.onConfirm;
  5. *@return {void}
  6. */
  7. function showModel(options) {
  8. options = options ? options : {};
  9. options.icon = options.icon ? options.icon : '';
  10. options.content = options.content ? options.content : '';
  11. options.showCancel = !!options.showCancel;
  12. options.cancelText = options.cancelText ? options.cancelText : '取消';
  13. options.confirmText = options.confirmText ? options.confirmText : '确认';
  14. options.onCancel = options.onCancel ? options.onCancel : function() {};
  15. options.onConfirm = options.onConfirm ? options.onConfirm : function() {};
  16. var model = '<div class="model">' +
  17. '<div class="model-wrapper">' +
  18. '<div class="model-box">' +
  19. '<div class="model-icon"><img src="' + options.icon + '" alt="" class="img"></div>' +
  20. '<div class="model-content">' + options.content + '</div>' +
  21. '</div>' +
  22. '<div class="model-btns">' +
  23. (options.showCancel ? '<div class="model-cancel">' + options.cancelText + '</div>' : '') +
  24. '<div class="model-confirm">' + options.confirmText + '</div>' +
  25. '</div>' +
  26. '</div>' +
  27. '</div>';
  28. $('body').append(model);
  29. $('.model-cancel').click(function() {
  30. $('.model').fadeOut(500).remove();
  31. options.onCancel();
  32. });
  33. $('.model-confirm').click(function() {
  34. $('.model').fadeOut(500).remove();
  35. options.onConfirm();
  36. });
  37. };
  38. // 使用
  39. showModel({
  40. content: '确认提交吗?',
  41. showCancel: true,
  42. cancelText: '取消',
  43. comfirmText: '确认',
  44. onCancel: function() {
  45. console.log('取消');
  46. },
  47. onComfirm: function() {
  48. console.log('确认');
  49. }
  50. })

CSS

  1. .toast {
  2. position: fixed;
  3. width: 100vw;
  4. height: 100vh;
  5. top: 0;
  6. left: 0;
  7. z-index: 100000;
  8. box-sizing: border-box;
  9. padding-top: 37.4vw;
  10. display: flex;
  11. flex-direction: column;
  12. justify-content: flex-start;
  13. align-items: center;
  14. }
  15. .toast .toast-wrapper {
  16. padding: 5vw;
  17. min-width: 18vw;
  18. background-color: rgba(0, 0, 0, .63);
  19. border-radius: 1.67vw;
  20. display: flex;
  21. flex-direction: column;
  22. justify-content: flex-start;
  23. align-items: center;
  24. }
  25. .toast .toast-wrapper .toast-icon {
  26. width: 8vw;
  27. height: 8vw;
  28. line-height: 0;
  29. margin-bottom: 2vw;
  30. }
  31. .toast .toast-wrapper .toast-content {
  32. max-width: 65vw;
  33. font-size: 3.73vw;
  34. color: #fff;
  35. line-height: 6.4vw;
  36. }
  37. .loading {
  38. position: fixed;
  39. width: 100vw;
  40. height: 100vh;
  41. top: 0;
  42. left: 0;
  43. z-index: 100000;
  44. box-sizing: border-box;
  45. padding-top: 37.4vw;
  46. display: flex;
  47. flex-direction: column;
  48. justify-content: flex-start;
  49. align-items: center;
  50. }
  51. .loading .loading-wrapper {
  52. padding: 5vw;
  53. min-width: 18vw;
  54. background-color: rgba(0, 0, 0, .63);
  55. border-radius: 1.67vw;
  56. display: flex;
  57. flex-direction: column;
  58. justify-content: flex-start;
  59. align-items: center;
  60. }
  61. .loading .loading-wrapper .loading-icon {
  62. width: 12vw;
  63. height: 12vw;
  64. border-radius: 50%;
  65. overflow: hidden;
  66. line-height: 0;
  67. margin-bottom: 2vw;
  68. }
  69. .loading .loading-wrapper .loading-content {
  70. max-width: 65vw;
  71. font-size: 3.73vw;
  72. color: #fff;
  73. line-height: 6.4vw;
  74. }
  75. .loading-btm {
  76. display: none;
  77. font-size: 3.2vw;
  78. color: #999;
  79. width: 100%;
  80. height: 8vw;
  81. line-height: 8vw;
  82. text-align: center;
  83. }
  84. .nomore {
  85. display: none;
  86. font-size: 3.2vw;
  87. color: #999;
  88. width: 100%;
  89. height: 8vw;
  90. line-height: 8vw;
  91. text-align: center;
  92. }
  93. .model {
  94. position: fixed;
  95. width: 100vw;
  96. height: 100vh;
  97. top: 0;
  98. left: 0;
  99. z-index: 100000;
  100. box-sizing: border-box;
  101. padding-top: 46vw;
  102. display: flex;
  103. flex-direction: column;
  104. justify-content: flex-start;
  105. align-items: center;
  106. background-color: rgba(0, 0, 0, .3)
  107. }
  108. .model .model-wrapper {
  109. width: 80vw;
  110. background-color: #ffffff;
  111. box-shadow: 0vw 0vw 3.2vw 0vw
  112. rgba(0, 0, 0, 0.05);
  113. border-radius: 1.6vw;
  114. overflow: hidden;
  115. }
  116. .model .model-wrapper .model-box {
  117. width: 100%;
  118. box-sizing: border-box;
  119. padding: 9vw 8vw 6vw 8vw;
  120. display: flex;
  121. flex-direction: column;
  122. justify-content: flex-start;
  123. align-items: center;
  124. }
  125. .model .model-wrapper .model-box .model-icon {
  126. width: 9.87vw;
  127. height: auto;
  128. line-height: 0;
  129. margin-bottom: 5.2vw;
  130. }
  131. .model .model-wrapper .model-box .model-content {
  132. font-size: 4.27vw;
  133. color: #333;
  134. line-height: 5.6vw;
  135. }
  136. .model .model-wrapper .model-btns {
  137. width: 100%;
  138. display: flex;
  139. flex-direction: row;
  140. justify-content: space-between;
  141. align-items: center;
  142. border-top: 1px solid #e2e2e2;
  143. }
  144. .model .model-wrapper .model-btns .model-cancel {
  145. box-sizing: border-box;
  146. flex: 1;
  147. height: 11.73vw;
  148. line-height: 11.73vw;
  149. text-align: center;
  150. font-size: 4.8vw;
  151. color: #999;
  152. border-right: 1px solid #e2e2e2;
  153. }
  154. .model .model-wrapper .model-btns .model-confirm {
  155. box-sizing: border-box;
  156. flex: 1;
  157. height: 11.73vw;
  158. line-height: 11.73vw;
  159. text-align: center;
  160. font-size: 4.8vw;
  161. color: #9966b4;
  162. }