前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Css3 Animation 动画原则七

Css3 Animation 动画原则七

作者头像
grain先森
发布2019-04-09 16:34:08
4120
发布2019-04-09 16:34:08
举报
文章被收录于专栏:grain先森grain先森

弧线运动 (Arc)

弧线运动

虽然对象是更逼真了,当它们遵循「缓入缓出」的时候它们很少沿直线运动——它们倾向于沿弧线运动。

我们有几种 CSS 的方式来实现弧线运动。一种是结合多个动画,比如在弹力球动画里,可以让球上下移动的同时让它右移,这时候球的显示效果就是沿弧线运动。

HTML
代码语言:javascript
复制
<h1>Principle 7: Arc (1)</h1>
<h2><a href="https://cssanimation.rocks/principles/" target="_parent">Animation Principles for the Web</h2>
<article class="principle sevena">
    <div class="shape-container">
      <div class="shape a"></div>
    </div>
</article>
CSS
代码语言:javascript
复制
.sevena .shape-container {
  animation: move-right 6s infinite cubic-bezier(.37,.55,.49,.67);
  position: absolute;
  left: calc(50% - 4em);
  top: calc(50% - 4em);
}
.sevena .shape {
  animation: bounce 6s infinite linear;
  border-radius: 50%;
  position: relative;
  left: auto;
  top: auto;
}

@keyframes move-right {
  0% {
    transform: translateX(-20em);
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  90%, 100% {
    transform: translateX(20em);
    opacity: 0;
  }
}

@keyframes bounce {
  0% {
    transform: translateY(-8em);
    animation-timing-function: cubic-bezier(.51,.01,.79,.02);
  }
  15% {
    transform: translateY(8em);
    animation-timing-function: cubic-bezier(.19,1,.7,1);
  }
  25% {
    transform: translateY(-4em);
    animation-timing-function: cubic-bezier(.51,.01,.79,.02);
  }
  32.5% {
    transform: translateY(8em);
    animation-timing-function: cubic-bezier(.19,1,.7,1);
  }
  40% {
    transform: translateY(0em);
    animation-timing-function: cubic-bezier(.51,.01,.79,.02);
  }
  45% {
    transform: translateY(8em);
    animation-timing-function: cubic-bezier(.19,1,.7,1);
  }
  50% {
    transform: translateY(3em);
    animation-timing-function: cubic-bezier(.51,.01,.79,.02);
  }
  56% {
    transform: translateY(8em);
    animation-timing-function: cubic-bezier(.19,1,.7,1);
  }
  60% {
    transform: translateY(6em);
    animation-timing-function: cubic-bezier(.51,.01,.79,.02);
  }
  64% {
    transform: translateY(8em);
    animation-timing-function: cubic-bezier(.19,1,.7,1);
  }
  66% {
    transform: translateY(7.5em);
    animation-timing-function: cubic-bezier(.51,.01,.79,.02);
  }
  70%, 100% {
    transform: translateY(8em);
    animation-timing-function: cubic-bezier(.19,1,.7,1);
  }
}

/* General styling */
body {
  margin: 0;
  background: #e9b59f;
  font-family: HelveticaNeue, Arial, Sans-serif;
  color: #fff;
}

h1 {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-weight: 300;
}

h2 {
  font-size: 0.75em;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
}

a {
  text-decoration: none;
  color: #333;
}

.principle {
  width: 100%;
  height: 100vh;
  position: relative;
}

.shape {
  background: #2d97db;
  border: 1em solid #fff;
  width: 4em;
  height: 4em;
  position: absolute;
  top: calc(50% - 2em);
  left: calc(50% - 2em);
}

另一种弧线运动

旋件运动

另外一种是旋转元件,我们可以设置一个在对象之外的原点来作为它的旋转中心。当我们旋转这个对象,它看上去就是沿着弧线运动。

HTML
代码语言:javascript
复制
<h1>Principle 7: Arc (2)</h1>
<h2><a href="https://cssanimation.rocks/principles/" target="_parent">Animation Principles for the Web</h2>
<article class="principle sevenb">
    <div class="shape a"></div>
    <div class="shape b"></div>
</article>
CSS
代码语言:javascript
复制
.sevenb .shape.a {
  animation: sevenb 3s infinite linear;
  top: calc(50% - 2em);
  left: calc(50% - 9em);
  transform-origin: 10em 50%;
}
.sevenb .shape.b {
  animation: sevenb 6s infinite linear reverse;
  background-color: yellow;
  width: 2em;
  height: 2em;
  left: calc(50% - 1em);
  top: calc(50% - 1em);
}

@keyframes sevenb {
  100% {
    transform: rotateZ(360deg);
  }
}

/* General styling */
body {
  margin: 0;
  background: #e9b59f;
  font-family: HelveticaNeue, Arial, Sans-serif;
  color: #fff;
}

h1 {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-weight: 300;
}

h2 {
  font-size: 0.75em;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
}

a {
  text-decoration: none;
  color: #333;
}

.principle {
  width: 100%;
  height: 100vh;
  position: relative;
}

.shape {
  background: #2d97db;
  border: 1em solid #fff;
  width: 4em;
  height: 4em;
  position: absolute;
  top: calc(50% - 2em);
  left: calc(50% - 2em);
} 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.03.31 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 弧线运动 (Arc)
  • 另一种弧线运动
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档