The difference between animation and transition

animation

/*1.animation-name:指定动画名称*/
animation-name: moveTest;
/*2.设置动画的总耗时*/
animation-duration: 2s;
/*3.动画的时间函数*/
animation-timing-function: linear;
/*4.设置动画的延迟*/
animation-delay: 0s;
/*5.设置动画的播放次数,默认为1次  可以指定具体的数值,也可以指定infinite(无限次)*/
animation-iteration-count: infinite;
/*6.设置交替动画  alternate:来回交替*/
animation-direction: alternate;
/*7.设置动画结束时的状态:默认情况下,动画执行完毕之后,会回到原始状态
forwards:会保留动画结束时的状态,在有延迟的情况下,并不会立刻进行到动画的初始状态
backwards:不会保留动画结束时的状态,在添加了动画延迟的前提下,如果动画有初始状态,那么会立刻进行到初始状态
both:会保留动画的结束时状态,在有延迟的情况下也会立刻进入到动画的初始状态*/
animation-fill-mode: both;
/*8.设置动画的播放状态  paused:暂停   running:播放*/
animation-play-state: running;
/*简写*/
animation: moveTest 2s linear 0s infinite alternate both;
@keyframes moveTest {
    
    
   0% {
    
     xx }
   50%{
    
     xx }
   100%{
    
     xx }
}

transition

It takes 2s to change opacity from 0 to 1 through transition

li {
    
    
   .hover-content {
    
    
        position: absolute;
        right: 12px;
        bottom: 28px;
        opacity: 0;
        transition: opacity 2s ;
	}
 	&:hover .hover-content {
    
    
        opacity:1
    }
}

Summary
1. Transition is a transition, the process of changing the style value. There are only beginning and end (only two frames). Animation can be combined with @keyframes to set the state of each frame;
2. Animation with @keyframes can be triggered without triggering time This process, and transition needs to be triggered through hover or js events;
3. Animation can set many properties, such as the number of cycles, the state of animation end, etc., transition can only be triggered once;

Guess you like

Origin blog.csdn.net/m0_48076809/article/details/107287830