当前位置:   article > 正文

CSS3-使用transform+animation实现圆弧渐变旋转动画,详细教程+源代码_html 圆形动画旋转代码

html 圆形动画旋转代码

最近组长要我研究一个开源网站的前端效果,其中有一个弧形旋转的动画,研究了下可以使用css里面的transform+animation组合实现。

先上效果图(忽略水印。。。视频转gif免费版的都有好大的水印)

 就是这样一个外圈有渐变移动的动画

实现步骤:

一、html代码:

  1. <div class="bj">
  2. <div class="bjzhuan"></div>//旋转的盒子
  3. <div class="hidBox"></div>//遮蔽的盒子
  4. </div>

 二、css代码:

1、先设置最外层盒子的背景

  1. .bj {
  2. width: 600px;
  3. height: 600px;
  4. background-image: url("../../../public/bj.svg");
  5. background-repeat: no-repeat;
  6. background-size: 100%;
  7. display: flex;
  8. align-items: center;
  9. position: relative;
  10. }

就是这样一个svg的图片

 2、设置需要旋转的盒子

  1. .bjzhuan {
  2. position: absolute;//设置绝对定位
  3. width: 600px;
  4. height: 300px;
  5. top: 0;
  6. left: 0;
  7. will-change: transform;//提高浏览器的页面渲染性能
  8. transform-origin: 50% 100%;//设置旋转中心,这里设置成该盒子(bjzhuan)宽的一半,高的全部,刚好就是父盒子(bj)的中心
  9. border-radius: 50% 50% 0 0/100% 100% 0 0;//为元素添加圆角边框,前的四个数值表示圆角的水平半径,后面四个值表示圆角的垂直半径
  10. background-image: linear-gradient(
  11. 60deg,
  12. rgba(109, 207, 251, 0) 0%,
  13. rgba(109, 207, 251, 0.2) 40%,
  14. rgba(109, 207, 251, 0) 100%
  15. );//实现渐变效果,60
  16. clip-path: polygon(100% 0, 20% 0%, 50% 100%, 0 100%, 0 0);//实现不规则图形,这里是四个坐标点,用逗号分隔开
  17. -webkit-transform: rotate(360deg);//实现360度旋转
  18. animation: rotation 3s linear infinite;
  19. -moz-animation: rotation 3s linear infinite;
  20. -webkit-animation: rotation 3s linear infinite;
  21. -o-animation: rotation 3s linear infinite;
  22. }
  23. @-webkit-keyframes rotation {
  24. from {
  25. -webkit-transform: rotate(0deg);
  26. }
  27. to {
  28. -webkit-transform: rotate(360deg);
  29. }
  30. }

此时的效果:

 这样一个圆弧三角,并且是360度旋转的。(我这里只截了个图,转成gif又得注册。。)

3、最后再设置遮蔽盒子的css

  1. .hidBox {
  2. height: 500px;
  3. width: 500px;
  4. position: absolute;
  5. background-color: #12131b;
  6. left: 50%;
  7. top: 50%;
  8. transform: translate(-50%, -50%);
  9. border-radius: 50%;
  10. z-index: 1;
  11. }

这样里面的三角部分就被挡住了,就会实现想要的效果

 大家有什么配置不懂的可以评论区留言,一起探讨

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/266158
推荐阅读
相关标签
  

闽ICP备14008679号