当前位置:Gxlcms > css > 如何用CSS3制作页面圆圈加载动画(附代码)

如何用CSS3制作页面圆圈加载动画(附代码)

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

打开页面时,经常会遇到页面正在加载的情况,作为一个前端工程师,你知道如何用CSS3实现页面加载动画效果吗?这篇文章就和大家分享一个炫酷的圆圈加载动画效果的代码,有一定的参考价值,感兴趣的朋友可以看看。

制作页面加载动画需要用到很多CSS3中的属性,比如:animation属性,position定位,border-radius圆角,transform属性等等,如有不清楚的同学可以看看我以前的文章,之前都有介绍过,或者访问 CSS3视频教程,这些都是基础,一定要掌握。

实例:制作一个圆圈加载动画效果,圆圈在加载时大小由小变大,颜色由浅变深,具体代码如下:

HTML部分:

  1. <div class="loader">
  2. <div class="loading">
  3. <i></i>
  4. <i></i>
  5. <i></i>
  6. <i></i>
  7. <i></i>
  8. <i></i>
  9. <i></i>
  10. <i></i>
  11. </div>
  12. </div>

CSS部分:

  1. .loader{
  2. width: 300px;
  3. border: 1px solid #ccc;
  4. height: 200px;
  5. display: flex;
  6. box-sizing: border-box;
  7. align-items: center;
  8. justify-content: center;
  9. }
  10. @-webkit-keyframes loading{
  11. 50%{
  12. transform: scale(0.4);
  13. opacity: 0.3;
  14. }
  15. 100%{
  16. transform: scale(1);
  17. opacity: 1;
  18. }
  19. }
  20. .loading{
  21. position: relative;
  22. }
  23. .loading i{
  24. display: block;
  25. width: 15px;
  26. height: 15px;
  27. border-radius: 50%;
  28. position: absolute;
  29. background: #333;
  30. }
  31. .loading i:nth-child(1){
  32. top: 25px;
  33. left: 0;
  34. -webkit-animation: loading 1s ease 0s infinite;
  35. }
  36. .loading i:nth-child(2){
  37. top: 17px;
  38. left: 17px;
  39. -webkit-animation: loading 1s ease 0.12s infinite;
  40. }
  41. .loading i:nth-child(3){
  42. top: 0;
  43. left: 25px;
  44. -webkit-animation: loading 1s ease 0.24s infinite;
  45. }
  46. .loading i:nth-child(4){
  47. top: -17px;
  48. left: 17px;
  49. -webkit-animation: loading 1s ease 0.36s infinite;
  50. }
  51. .loading i:nth-child(5){
  52. top: -25px;
  53. left: 0;
  54. -webkit-animation: loading 1s ease 0.48s infinite;
  55. }
  56. .loading i:nth-child(6){
  57. top: -17px;
  58. left: -17px;
  59. -webkit-animation: loading 1s ease 0.6s infinite;
  60. }
  61. .loading i:nth-child(7){
  62. top: 0;
  63. left: -25px;
  64. -webkit-animation: loading 1s ease 0.72s infinite;
  65. }
  66. .loading i:nth-child(8){
  67. top: 17px;
  68. left: -17px;
  69. -webkit-animation: loading 1s ease 0.84s infinite;
  70. }

效果图:

图片aa.jpg

以上分享了CSS3实现页面加载动画效果的代码,项目中用的比较多,可以直接拿过去使用,也希望大家可以自己动手尝试,看看自己能不能写出其他的效果,希望这篇文章对你有所帮助!更多相关教程请访问 CSS视频教程

以上就是如何用CSS3制作页面圆圈加载动画(附代码)的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行