[关闭]
@pspgbhu 2018-02-05T17:15:36.000000Z 字数 556 阅读 1000

小明的正确答案

temp


通常最好的动画方式是使用 CSS Animation。下面是一个简单的示例:

  1. @keyframes slidein {
  2. from {
  3. transform: scale(1);
  4. }
  5. to {
  6. transform: scale(0);
  7. }
  8. }
  9. .animation {
  10. animation: 3s linear slidein;
  11. }
  12. .target {
  13. width: 100px;
  14. height: 100px;
  15. will-change: transform;
  16. }
  1. // 为 .target 元素来添加动画
  2. document.querySelector('.target').classList.add('animation');

或者,用 transform + transition 来完成动画也是不错的:

  1. .target {
  2. width: 100px;
  3. height: 100px;
  4. transform: scale(1);
  5. transition: transform 1s linear;
  6. will-change: transform;
  7. }
  8. .scale {
  9. transform: scale(0);
  10. }
  1. // 为 .target 元素来添加动画
  2. document.querySelector('.target').classList.add('scale');

总而言之,就是将动画的计算交给浏览器去做,而不是在 JS 中做。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注