HTML/CSS

用纯CSS打造圆形图片旋转的方法

阿里云

上次看到一个博客的 LOGO 图片很好看,一个旋转的圆形人物图片,但是我看他用了大量的 JS 代码来渲染这个效果。其实这种方式纯 CSS3 是完全可以实现,我们只需要考虑清楚我们的思路。

1、圆形图片

我们这里使用了一张哈弗 H2 的图片。

然后把图片写成圆形。

也想出现在这里?联系我们
创客主机
  1. height: 300px;
  2. width: 300px;
  3. border-radius: 150px;

2、将图片旋转

这里我们使用了动画 keyframes,将图片不停的自转

  1. animation: 9.5s linear 0s normal none infinite rotate;

3、图片外面遮罩

这里我们使用了遮罩层将我们上面的图片遮罩起来,这样子就看到了一个旋转的图片在一个灰色的背景上面。

  1. <div class="cover"></div>

下面是所有完整的代码:

  1. <style>
  2. @-webkit-keyframes rotate{
  3. 	from{-webkit-transform:rotate(0deg)}
  4. 	to{-webkit-transform:rotate(360deg)}
  5. 	}
  6. @-moz-keyframes rotate{
  7. 	from{-moz-transform:rotate(0deg)}
  8. 	to{-moz-transform:rotate(360deg)}
  9. 	}
  10. @-ms-keyframes rotate{
  11. 	from{-ms-transform:rotate(0deg)}
  12. 	to{-ms-transform:rotate(360deg)}
  13. 	}
  14. @-o-keyframes rotate{
  15. 	from{-o-transform:rotate(0deg)}
  16. 	to{-o-transform:rotate(360deg)}
  17. 	}
  18.  
  19. .image{
  20. 	background-image: url('https://www.22vd.com/wp-content/uploads/2018/11/2018110811355585.jpg');
  21. 	background-repeat: no-repeat;
  22. 	animation: 9.5s linear 0s normal none infinite rotate;
  23. 	-webkit-animation:9.5s linear 0s normal none infinite rotate;
  24. 	height: 300px;
  25. 	width: 300px;
  26.         border-radius: 150px;
  27. 	position: absolute;
  28. 	top: 74px;
  29. 	left: 73px;
  30. 	z-index: 0;
  31. }
  32.  
  33. .cover{
  34. 	background:#eee;
  35. 	height:430px;
  36. 	width:430px;
  37. 	position:absolute;
  38. }
  39. </style>
  40.  
  41. <div>
  42.     <div class="cover"></div>
  43.     <div class="image">
  44.     </div>
  45. </div>

用纯 CSS 打造圆形图片旋转的方法

已有 953 人购买
查看演示升级 VIP立刻购买

收藏
(4)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!