当前位置:Gxlcms > AJAX > js ajax加载时的进度条代码

js ajax加载时的进度条代码

时间:2021-07-01 10:21:17 帮助过:46人阅读

最终效果如下图所示,pc和移动端都可以展示的,调用方法也很简单,开始调用:loading.baosight.showPageLoadingMsg(false),alse代表不现实加载说明,true展示加载说明.调用完成后调用:loading.baosight.hidePageLoadingMsg(),在整个代码里有两个文件,一个是js文件,一个是css文件。切记不要忘记引入jquery.js

css文件

  1. #_loadMsg{
  2. display: inline-block;
  3. width: 100%;
  4. text-align: center;
  5. line-height: 45;
  6. padding-left: 20px;
  7. display : none;
  8. }
  9. #_loading_div {
  10. vertical-align: middle;
  11. display: inline-block;
  12. width: 100%;
  13. height: 100%;
  14. margin: 0 auto;
  15. text-align: center;
  16. position: absolute;
  17. z-index: 3;
  18. line-height: 40;
  19. opacity: 0.5;
  20. display : none;
  21. background: #CCCCCC;
  22. }
  23. #_loading_div span {
  24. display: inline-block;
  25. width: 10px;
  26. height: 40px;
  27. animation-name: scale;
  28. -webkit-animation-name: scale;
  29. -moz-animation-name: scale;
  30. -ms-animation-name: scale;
  31. -o-animation-name: scale;
  32. animation-duration: 1.2s;
  33. -webkit-animation-duration: 1.2s;
  34. -moz-animation-duration: 1.2s;
  35. -ms-animation-duration: 1.2s;
  36. -o-animation-duration: 1.2s;
  37. animation-iteration-count: infinite;
  38. -webkit-animation-iteration-count: infinite;
  39. -moz-animation-iteration-count: infinite;
  40. -ms-animation-iteration-count: infinite;
  41. -o-animation-iteration-count: infinite;
  42. }
  43. span.item-1 {
  44. background: #2ecc71;
  45. }
  46. span.item-2 {
  47. background: #3498db;
  48. }
  49. span.item-3 {
  50. background: #9b59b6;
  51. }
  52. span.item-4 {
  53. background: #e67e22;
  54. }
  55. span.item-5 {
  56. background: #c0392b;
  57. }
  58. span.item-6 {
  59. background: #e74c3c;
  60. }
  61. span.item-7 {
  62. background: #e74c8c;
  63. }
  64. .item-1 {
  65. animation-delay: -1s;
  66. -webkit-animation-delay: -1s;
  67. -moz-animation-delay: -1s;
  68. -ms-animation-delay: -1s;
  69. -o-animation-delay: -1s;
  70. }
  71. .item-2 {
  72. animation-delay: -0.9s;
  73. -webkit-animation-delay: -0.9s;
  74. -moz-animation-delay: -0.9s;
  75. -ms-animation-delay: -0.9s;
  76. -o-animation-delay: -0.9s;
  77. }
  78. .item-3 {
  79. animation-delay: -0.8s;
  80. -webkit-animation-delay: -0.8s;
  81. -moz-animation-delay: -0.8s;
  82. -ms-animation-delay: -0.8s;
  83. -o-animation-delay: -0.8s;
  84. }
  85. .item-4 {
  86. animation-delay: -0.7s;
  87. -webkit-animation-delay: -0.7s;
  88. -moz-animation-delay: -0.7s;
  89. -ms-animation-delay: -0.7s;
  90. -o-animation-delay: -0.7s;
  91. }
  92. .item-5 {
  93. animation-delay: -0.6s;
  94. -webkit-animation-delay: -0.6s;
  95. -moz-animation-delay: -0.6s;
  96. -ms-animation-delay: -0.6s;
  97. -o-animation-delay: -0.6s;
  98. }
  99. .item-6 {
  100. animation-delay: -0.5s;
  101. -webkit-animation-delay: -0.5s;
  102. -moz-animation-delay: -0.5s;
  103. -ms-animation-delay: -0.5s;
  104. -o-animation-delay: -0.5s;
  105. }
  106. .item-7 {
  107. animation-delay: -0.4s;
  108. -webkit-animation-delay: -0.4s;
  109. -moz-animation-delay: -0.4s;
  110. -ms-animation-delay: -0.4s;
  111. -o-animation-delay: -0.4s;
  112. }
  113. @-webkit-keyframes scale {
  114. 0%, 40%, 100% {
  115. -moz-transform: scaleY(0.2);
  116. -ms-transform: scaleY(0.2);
  117. -o-transform: scaleY(0.2);
  118. -webkit-transform: scaleY(0.2);
  119. transform: scaleY(0.2);
  120. }
  121. 20%, 60% {
  122. -moz-transform: scaleY(1);
  123. -ms-transform: scaleY(1);
  124. -o-transform: scaleY(1);
  125. -webkit-transform: scaleY(1);
  126. transform: scaleY(1);
  127. }
  128. }
  129. @-moz-keyframes scale {
  130. 0%, 40%, 100% {
  131. -moz-transform: scaleY(0.2);
  132. -ms-transform: scaleY(0.2);
  133. -o-transform: scaleY(0.2);
  134. -webkit-transform: scaleY(0.2);
  135. transform: scaleY(0.2);
  136. }
  137. 20%, 60% {
  138. -moz-transform: scaleY(1);
  139. -ms-transform: scaleY(1);
  140. -o-transform: scaleY(1);
  141. -webkit-transform: scaleY(1);
  142. transform: scaleY(1);
  143. }
  144. }
  145. @-ms-keyframes scale {
  146. 0%, 40%, 100% {
  147. -moz-transform: scaleY(0.2);
  148. -ms-transform: scaleY(0.2);
  149. -o-transform: scaleY(0.2);
  150. -webkit-transform: scaleY(0.2);
  151. transform: scaleY(0.2);
  152. }
  153. 20%, 60% {
  154. -moz-transform: scaleY(1);
  155. -ms-transform: scaleY(1);
  156. -o-transform: scaleY(1);
  157. -webkit-transform: scaleY(1);
  158. transform: scaleY(1);
  159. }
  160. }
  161. @keyframes scale {
  162. 0%, 40%, 100% {
  163. -moz-transform: scaleY(0.2);
  164. -ms-transform: scaleY(0.2);
  165. -o-transform: scaleY(0.2);
  166. -webkit-transform: scaleY(0.2);
  167. transform: scaleY(0.2);
  168. }
  169. 20%, 60% {
  170. -moz-transform: scaleY(1);
  171. -ms-transform: scaleY(1);
  172. -o-transform: scaleY(1);
  173. -webkit-transform: scaleY(1);
  174. transform: scaleY(1);
  175. }
  176. }

js文件

  1. var loading = {
  2. baosight : {
  3. showPageLoadingMsg : function(showMessage){
  4. if($("#_loading_div").length == 0){
  5. $("body").append('<div id="_loading_div"><span class="item-1"></span><span class="item-2"></span><span class="item-3"></span><span class="item-4"></span><span class="item-5"></span><span class="item-6"></span><span class="item-7"></span></div>');
  6. }
  7. if($("#_loadMsg").length == 0){
  8. $("body").append('<div id="_loadMsg">正在加载,请稍候... ...</div>');
  9. }
  10. if(showMessage == true || showMessage == "true" ){
  11. $("#_loadMsg").show();
  12. }
  13. $("#_loading_div").show();
  14. },
  15. hidePageLoadingMsg :function() {
  16. $("#_loading_div").hide();
  17. $("#_loadMsg").hide();
  18. }
  19. }
  20. }

以上内容是本文的全部叙述,希望大家喜欢。

人气教程排行