Mus*_*man 5 html css typescript angular2-template
我是这个编码领域的新手,我认为我的问题很简单,对于像你们这些人一样有经验的人.我正在尝试为按钮内部的图像设置动画.当我点击按钮时,我需要将图像旋转360度.我不知道我在做什么错误是我的HTML和CSS代码.请帮忙
.syncRotate {
-webkit-transition: 500ms ease all !important;
-moz-transition: 500ms ease all !important;
-o-transition: 500ms ease all !important;
transition: 500ms ease all !important;
-webkit-transform: rotate(360deg) !important;
}
Run Code Online (Sandbox Code Playgroud)
<button class="iconBtn" mdTooltipPosition="above" mdTooltip="Sync User" (click)="sync()">
<img class="syncRotate" style="width:20px;background-color: #a6a6a6;border-radius: 13px;padding:2px;" src="../../assets/images/icons/sync.svg" alt="Sync">
</button>
Run Code Online (Sandbox Code Playgroud)
如果您只想使用过渡,这将适合您。!
.syncRotate {
-webkit-transition: 500ms ease all;
-moz-transition: 500ms ease all;
-o-transition: 500ms ease all;
transition: 500ms ease all;
-webkit-transform: rotate(0deg);
}
.syncRotate:active {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
Run Code Online (Sandbox Code Playgroud)
<button class="iconBtn" mdTooltipPosition="above" mdTooltip="Sync User" (click)="sync()">
<img class="syncRotate" style="width:20px;background-color: #a6a6a6;border-radius: 13px;padding:2px;" src="https://lh6.ggpht.com/bE_u2kFoX28G428YH1jpWTMoaZ3B9cokstrKxD82zj7hoBNL-U1wiAVddau3mvvUpPoD=w300" alt="Sync">
</button>
Run Code Online (Sandbox Code Playgroud)
如果你想让它使用CSS 动画制作漂亮的动画
@keyframes rotation {
0% {
-webkit-transform: rotate(0deg);
}
50% {
-webkit-transform: rotate(360deg);
}
100% {
-webkit-transform: rotate(0deg);
}
}
.syncRotate {
-webkit-transform: rotate(0deg);
}
.syncRotate:active {
animation: rotation 500ms ease-in-out forwards;
}
Run Code Online (Sandbox Code Playgroud)
<button class="iconBtn" mdTooltipPosition="above" mdTooltip="Sync User" (click)="sync()">
<img class="syncRotate" style="width:20px;background-color: #a6a6a6;border-radius: 13px;padding:2px;" src="https://lh6.ggpht.com/bE_u2kFoX28G428YH1jpWTMoaZ3B9cokstrKxD82zj7hoBNL-U1wiAVddau3mvvUpPoD=w300" alt="Sync">
</button>
Run Code Online (Sandbox Code Playgroud)
通过将500ms 更改为 400ms 左右,我们可以使其变得更快,将其更改得更高将使动画和过渡变慢,例如 900ms 或 1s。
注意:因为我们只使用 CSS,所以动画和过渡仅在用户单击按钮时才会出现。所以在你的情况下两者都是一样的。