使用Animation

css实现

常见属性

.square {
  width: 100px;
  height: 100px;
  background-color: gold;
  animation-name: move;
  animation-duration: 2s;
  animation-delay: 0s;
  animation-timing-function: linear;
  animation-iteration-count: 2;
  animation-direction: alternate;
  animation-play-state: paused;
  /* animation: 2s 0s 2 alternate running move;*/
}

@keyframes move {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(calc(100vw - 140px));
  }
}

注意:animation-direction: alternate与animation-direction: reverse是不同的逻辑!

animation-play-state: paused光写在css中没有什么意义,与js结合动态赋予css选择器才有作用。 

 animation composition

假设我们有以下两个动画:

.square {
  width: 100px;
  height: 100px;
  background-color: gold;
  transform: rotate(45deg); 
  animation: 2s ease-in-out infinite alternate move,
    0.3s ease-in-out infinite alternate bounce;
  animation-composition: add
}


@keyframes move {
  0% {
    transform: translateX(0) rotate(45deg);
  }
  100% {
    transform: translateX(calc(100vw - 140px));
  }
}

@keyframes bounce {
  0% {
    transform: translateY(0);
    /* margin-top: 0px; */
  }
  100% {
    transform: translateY(100px);
    /* margin-top: 100px; */
  }
}

/* animation-composition: replace;
  0% -> transform: translateX(0);
  100% -> transform: translateX(calc(100vw - 140px));
*/
/* animation-composition: add;
  0% -> transform: rotate(45deg) translateX(0) rotate(45deg);
  100% -> transform: rotate(45deg) translateX(calc(100vw - 140px));
*/
/* animation-composition: accumulate;
  0% -> transform: translateX(0) rotate(90deg);
  100% -> transform: rotate(45deg) translateX(calc(100vw - 140px)) ;
*/

默认情况下,animation-composition:replace,后面的动画会把前面的动画相同属性覆盖掉,如果你想共同起作用设置如下:animation-composition: add。如果你想把其中一些变换累计在一起的最后  ,设置如下:animation-composition: accumulate

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值