[英]CSS rotate animation with pulse
I am trying to make an animation using CSS. 我正在尝试使用CSS制作动画。 It should rotate an image and give it a pulse (something similar to Shazam's button animation).
它应该旋转图像并为其提供脉冲(类似于Shazam的按钮动画)。 The following is my code.
以下是我的代码。 Image is rotating but if I add 'scale' to try and make it pulsate as well, it has a pulse but does not rotate.
图像正在旋转,但是如果我添加“比例”以尝试使其也产生脉动,则它具有脉冲但不会旋转。
.animated {
animation-duration: 5s;
-webkit-animation-duration: 5s;
animation-fill-mode: none;
-webkit-animation-fill-mode: none;
animation-timing-function: linear;
-webkit-animation-timing-function: linear;
animation-iteration-count: infinite;
-webkit-animation-iteration-count: infinite;
}
@keyframes rotate {
0% {
/*transform: scale(1);*/
transform-origin: center center;
transform: rotate(-360deg);
}
50% {
/*transform: scale(1.1);*/
transform-origin: center center;
}
100% {
/*transform: scale(1);*/
transform-origin: center center;
transform: rotate(0);
}
}
@-webkit-keyframes rotate {
0% {
/*-webkit-transform: scale(1);*/
-webkit-transform-origin: center center;
-webkit-transform: rotate(-360deg);
}
50% {
/*-webkit-transform: scale(1.1);*/
-webkit-transform-origin: center center;
}
100% {
/*-webkit-transform: scale(1);*/
-webkit-transform-origin: center center;
-webkit-transform: rotate(0);
}
}
.rotate {
animation-name: rotate;
-webkit-animation-name: rotate;
}
Could someone please help? 有人可以帮忙吗?
This is a guess since I don't know how you html (markup). 这是一个猜测,因为我不知道您如何使用html(标记)。
You have to add all the transform properties on each step in the keyframe. 您必须在关键帧的每个步骤上添加所有变换属性。
So if any of the keyframes have sett: transform: scale(2);
因此,如果有任何关键帧已设置:
transform: scale(2);
Then it will only scale. 然后它只会缩放。
So you have to set all the transfrom properties on all keyframes. 因此,您必须在所有关键帧上设置所有transfrom属性。
eg. 例如。
transfrom: scale(value) rotate(value);
on every keyframe. 在每个关键帧上。
.animated { animation-duration: 5s; -webkit-animation-duration: 5s; animation-fill-mode: none; -webkit-animation-fill-mode: none; animation-timing-function: linear; -webkit-animation-timing-function: linear; animation-iteration-count: infinite; -webkit-animation-iteration-count: infinite; } @keyframes rotate { 0% { /*transform: scale(1);*/ transform-origin: center center; transform: rotate(-360deg) scale(1); } 50% { /*transform: scale(1.1);*/ transform-origin: center center; transform: rotate(-180deg) scale(0.1); } 100% { /*transform: scale(1);*/ transform-origin: center center; transform: rotate(0) scale(1); } } @-webkit-keyframes rotate { 0% { /*-webkit-transform: scale(1);*/ -webkit-transform-origin: center center; -webkit-transform: rotate(-360deg) scale(1); } 50% { /*-webkit-transform: scale(1.1);*/ -webkit-transform-origin: center center; -webkit-transform: rotate(-180deg) scale(0.1); } 100% { /*-webkit-transform: scale(1);*/ -webkit-transform-origin: center center; -webkit-transform: rotate(0) scale(1); } } .rotate { animation-name: rotate; -webkit-animation-name: rotate; }
<div> <img class="animated rotate" src="http://lorempixel.com/400/200" /> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.