纯Css实现加载动画效果

效果:

            

代码实现: 


  
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Loading</title>
  6. <style>
  7. * {
  8. margin: 0em;
  9. padding: 0em;
  10. }
  11. .loader {
  12. position: absolute;
  13. top: 50%;
  14. left: 50%;
  15. -webkit-transform: translate(-50%, -50%);
  16. -moz-transform: translate(-50%, -50%);
  17. -mos-transform: translate(-50%, -50%);
  18. -o-transform: translate(-50%, -50%);
  19. transform: translate(-50%, -50%);
  20. text-align: center;
  21. -webkit-touch-callout: none;
  22. -webkit-user-select: none;
  23. -khtml-user-select: none;
  24. -moz-user-select: none;
  25. -ms-user-select: none;
  26. user-select: none;
  27. cursor: default;
  28. }
  29. .text {
  30. position: absolute;
  31. left: -1.3em;
  32. top: -1.7em;
  33. -webkit-animation: text 2s infinite;
  34. -moz-animation: text 2s infinite;
  35. -moz-animation: text 2s infinite;
  36. -ms-animation: text 2s infinite;
  37. -o-animation: text 2s infinite;
  38. animation: text 2s infinite;
  39. }
  40. .horizontal {
  41. position: absolute;
  42. top: 0em;
  43. left: 0em;
  44. -webkit-transform: rotate(0deg);
  45. -moz-transform: rotate(0deg);
  46. -ms-transform: rotate(0deg);
  47. -o-transform: rotate(0deg);
  48. transform: rotate(0deg);
  49. }
  50. .circlesup {
  51. position: absolute;
  52. top: -4.7em;
  53. right: 12.1em;
  54. }
  55. .circle {
  56. position: absolute;
  57. width: 15em;
  58. height: 15em;
  59. -webkit-transform: rotate(45deg);
  60. -moz-transform: rotate(45deg);
  61. -ms-transform: rotate(45deg);
  62. -o-transform: rotate(45deg);
  63. transform: rotate(45deg);
  64. -webkit-animation: orbit 2s infinite;
  65. -moz-animation: orbit 2s infinite;
  66. -moz-animation: orbit 2s infinite;
  67. -ms-animation: orbit 2s infinite;
  68. -o-animation: orbit 2s infinite;
  69. animation: orbit 2s infinite;
  70. z-index: 5;
  71. }
  72. .circle:after {
  73. content: '';
  74. position: absolute;
  75. width: 2em;
  76. height: 2em;
  77. -webkit-border-radius: 100%;
  78. -moz-border-radius: 100%;
  79. -ms-border-radius: 100%;
  80. -o-border-radius: 100%;
  81. border-radius: 100%;
  82. background: #17b2f0;
  83. }
  84. .circle:nth-child(2) {
  85. -webkit-animation-delay: 100ms;
  86. -moz-animation-delay: 100ms;
  87. -ms-animation-delay: 100ms;
  88. -o-animation-delay: 100ms;
  89. animation-delay: 100ms;
  90. z-index: 4;
  91. }
  92. .circle:nth-child(2):after {
  93. background: #59b9e0;
  94. -webkit-transform: scale(0.8, 0.8);
  95. -moz-transform: scale(0.8, 0.8);
  96. -ms-transform: scale(0.8, 0.8);
  97. -o-transform: scale(0.8, 0.8);
  98. transform: scale(0.8, 0.8);
  99. }
  100. .circle:nth-child(3) {
  101. -webkit-animation-delay: 225ms;
  102. -moz-animation-delay: 225ms;
  103. -ms-animation-delay: 225ms;
  104. -o-animation-delay: 225ms;
  105. animation-delay: 225ms;
  106. z-index: 3;
  107. }
  108. .circle:nth-child(3):after {
  109. background: #ffa489;
  110. -webkit-transform: scale(0.6, 0.6);
  111. -moz-transform: scale(0.6, 0.6);
  112. -ms-transform: scale(0.6, 0.6);
  113. -o-transform: scale(0.6, 0.6);
  114. transform: scale(0.6, 0.6);
  115. }
  116. .circle:nth-child(4) {
  117. -webkit-animation-delay: 350ms;
  118. -moz-animation-delay: 350ms;
  119. -ms-animation-delay: 350ms;
  120. -o-animation-delay: 350ms;
  121. animation-delay: 350ms;
  122. z-index: 2;
  123. }
  124. .circle:nth-child(4):after {
  125. background: #ff6d37;
  126. -webkit-transform: scale(0.4, 0.4);
  127. -moz-transform: scale(0.4, 0.4);
  128. -ms-transform: scale(0.4, 0.4);
  129. -o-transform: scale(0.4, 0.4);
  130. transform: scale(0.4, 0.4);
  131. }
  132. .circle:nth-child(5) {
  133. -webkit-animation-delay: 475ms;
  134. -moz-animation-delay: 475ms;
  135. -ms-animation-delay: 475ms;
  136. -o-animation-delay: 475ms;
  137. animation-delay: 475ms;
  138. z-index: 1;
  139. }
  140. .circle:nth-child(5):after {
  141. background: #DB2F00;
  142. -webkit-transform: scale(0.2, 0.2);
  143. -moz-transform: scale(0.2, 0.2);
  144. -ms-transform: scale(0.2, 0.2);
  145. -o-transform: scale(0.2, 0.2);
  146. transform: scale(0.2, 0.2);
  147. }
  148. .circlesdwn {
  149. position: absolute;
  150. top: 2.5em;
  151. right: -13.5em;
  152. -webkit-transform: rotate(180deg);
  153. -moz-transform: rotate(180deg);
  154. -ms-transform: rotate(180deg);
  155. -o-transform: rotate(180deg);
  156. transform: rotate(180deg);
  157. }
  158. .vertical {
  159. position: absolute;
  160. top: -1.84em;
  161. left: -0.4em;
  162. -webkit-transform: rotate(90deg);
  163. -moz-transform: rotate(90deg);
  164. -ms-transform: rotate(90deg);
  165. -o-transform: rotate(90deg);
  166. transform: rotate(90deg);
  167. }
  168. @-webkit-keyframes text {
  169. 0% {
  170. transform: scale(.2, .2);
  171. animation-timing-function: ease-out;
  172. }
  173. 50% {
  174. transform: scale(1, 1);
  175. animation-timing-function: ease-out;
  176. }
  177. 60% {
  178. transform: scale(1, 1);
  179. animation-timing-function: ease-out;
  180. }
  181. 100% {
  182. transform: scale(.2, .2);
  183. }
  184. }
  185. @keyframes text {
  186. 0% {
  187. transform: scale(.2, .2);
  188. animation-timing-function: ease-out;
  189. }
  190. 50% {
  191. transform: scale(1, 1);
  192. animation-timing-function: ease-out;
  193. }
  194. 60% {
  195. transform: scale(1, 1);
  196. animation-timing-function: ease-out;
  197. }
  198. 100% {
  199. transform: scale(.2, .2);
  200. }
  201. }
  202. @-webkit-keyframes orbit {
  203. 0% {
  204. transform: rotate(45deg);
  205. }
  206. 5% {
  207. transform: rotate(45deg);
  208. animation-timing-function: ease-out;
  209. }
  210. 70% {
  211. transform: rotate(405deg);
  212. animation-timing-function: ease-in;
  213. }
  214. 100% {
  215. transform: rotate(405deg);
  216. }
  217. }
  218. @keyframes orbit {
  219. 0% {
  220. transform: rotate(45deg);
  221. }
  222. 5% {
  223. transform: rotate(45deg);
  224. animation-timing-function: ease-out;
  225. }
  226. 70% {
  227. transform: rotate(405deg);
  228. animation-timing-function: ease-in;
  229. }
  230. 100% {
  231. transform: rotate(405deg);
  232. }
  233. }
  234. #content {
  235. width: 100%;
  236. height: 100%;
  237. opacity: 0;
  238. transition: opacity 0.5s;
  239. }
  240. #content iframe {
  241. width: 100%;
  242. height: -webkit-fill-available;
  243. }
  244. </style>
  245. </head>
  246. <body>
  247. <div class="loader" id="loader">
  248. <div class="text">Loading...</div>
  249. <div class="horizontal">
  250. <div class="circlesup">
  251. <div class="circle"></div>
  252. <div class="circle"></div>
  253. <div class="circle"></div>
  254. <div class="circle"></div>
  255. <div class="circle"></div>
  256. </div>
  257. <div class="circlesdwn">
  258. <div class="circle"></div>
  259. <div class="circle"></div>
  260. <div class="circle"></div>
  261. <div class="circle"></div>
  262. <div class="circle"></div>
  263. </div>
  264. </div>
  265. <div class="vertical">
  266. <div class="circlesup">
  267. <div class="circle"></div>
  268. <div class="circle"></div>
  269. <div class="circle"></div>
  270. <div class="circle"></div>
  271. <div class="circle"></div>
  272. </div>
  273. <div class="circlesdwn">
  274. <div class="circle"></div>
  275. <div class="circle"></div>
  276. <div class="circle"></div>
  277. <div class="circle"></div>
  278. <div class="circle"></div>
  279. </div>
  280. </div>
  281. </div>
  282. <div id="content">
  283. <iframe src="//www.albertyy.com"></iframe>
  284. </div>
  285. </body>
  286. <script>
  287. document.onreadystatechange = loadingChange; //当页面加载状态改变的时候执行这个方法.
  288. function loadingChange() {
  289. if (document.readyState == "complete") { //当页面加载状态为完全结束时进入
  290. document.getElementById("loader").style.display = "none";
  291. document.getElementById("content").style.opacity = 1;
  292. }
  293. }
  294. </script>
  295. </html>

 

文章来源: albertyang.blog.csdn.net,作者:Albert Yang,版权归原作者所有,如需转载,请联系作者。

原文链接:albertyang.blog.csdn.net/article/details/107083268

(完)