我们在进行网页页面设计时,经常会遇到各种关于图片展示的问题,比如有的需要让图片圆角展示、图片旋转等等效果。下面我们来看一下如何实现图片旋转效果。
我们可以给img图片添加了transform和animation样式属性来实现图片旋转效果。
示例:
HTML代码:
css代码:.demo{text-align: center;
margin-top: 100px;}
@-webkit-keyframes rotation{
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(360deg);}
}
.an{
-webkit-transform: rotate(360deg);
animation: rotation 3s linear infinite;
-moz-animation: rotation 3s linear infinite;
-webkit-animation: rotation 3s linear infinite;
-o-animation: rotation 3s linear infinite;
}
.img{border-radius: 250px;}
我们给img图片添加了transform和animation样式属性,使得图片实现360度旋转动画效果。
css动画图片自动旋转的效果实现方法,也就如上所述。只要掌握了css中的transform和animation属性就可以实现大多数动画效果。他们的原理基本都是大同小异。
transform 属性向元素应用 2D 或 3D 转换。该属性允许我们对元素进行旋转、缩放、移动或倾斜。通过 rotate() 方法,元素顺时针旋转给定的角度。允许负值,元素将逆时针旋转。
animation属性是一个简写属性,用于设置六个动画属性:animation-name 规定需要绑定到选择器的 keyframe 名称。
animation-duration 规定完成动画所花费的时间,以秒或毫秒计。
animation-timing-function 规定动画的速度曲线。
animation-delay 规定在动画开始之前的延迟。
animation-iteration-count 规定动画应该播放的次数。
animation-direction 规定是否应该轮流反向播放动画。