CSS 动画制作的 12 个技巧,字节跳动前端面试题解析

.shape {

background: #2d97db;

border: 1em solid #fff;

width: 4em;

height: 4em;

position: absolute;

top: calc(50% - 2em);

left: calc(50% - 2em);

}

五、跟随和重叠动作 (Follow Through and Overlapping Action)

事情并不总在同一时间发生。当一辆车从急刹到停下,车子会向前倾、有烟从轮胎冒出来、车里的司机继续向前冲。

这些细节是跟随和重叠动作的例子。它们在网页中能被用作帮助强调什么东西被停止,并不会被遗忘。例如一个条目可能在滑动时稍滑微远了些,但它自己会纠正到正确位置。

要创造一个重叠动作的感觉,我们可以让元件以稍微不同的速度移动到每处。这是一种在 iOS 系统的视窗 过渡中被运用得很好的方法。一些按钮和元件以不同速率运动,整体效果会比全部东西以相同速率运动要更逼真,并留出时间让访客去适当理解变化。

在网页方面,这可能意味着让过渡或动画的效果以不同速度来运行。

.five .shape {

animation: five 4s infinite cubic-bezier(.64,-0.36,.1,1);

position: relative;

left: auto;

top: auto;

}

.five .shape-container {

animation: five-container 4s infinite cubic-bezier(.64,-0.36,.1,2);

position: absolute;

left: calc(50% - 4em);

top: calc(50% - 4em);

}

@keyframes five {

0%, 15% {

opacity: 0;

transform: translateX(-12em);

}

15%, 25% {

transform: translateX(-12em);

opacity: 1;

}

85%, 90% {

transform: translateX(12em);

opacity: 1;

}

100% {

transform: translateX(12em);

opacity: 0;

}

}

@keyframes five-container {

0%, 35% {

transform: none;

}

50%, 60% {

transform: skewX(20deg);

}

90%, 100% {

transform: none;

}

}

.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);

}

六、缓入缓出 (Slow In and Slow Out)

对象很少从静止状态一下子加速到最大速度,它们往往是逐步加速并在停止前变慢。没有加速和减速,动画感觉就像机器人。

在 CSS 方面,缓入缓出很容易被理解,在一个动画过程中计时功能是一种描述变化速率的方式。

使用计时功能,动画可以由慢加速 (ease-in)、由快减速 (ease-out),或者用贝塞尔曲线做出更复杂的效果。

.six .shape {

animation: six 3s infinite cubic-bezier(0.5,0,0.5,1);

}

@keyframes six {

0%, 5% {

transform: translate(-12em);

}

45%, 55% {

transform: translate(12em);

}

95%, 100% {

transform: translate(-12em);

}

}

.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);

}

七、弧线运动 (Arc)

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

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

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

.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);

}

}

.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);

}

八、次要动作 (Secondary Action)

虽然主动画正在发生,次要动作可以增强它的效果。这就好比某人在走路的时候摆动手臂和倾斜脑袋,或者弹性球弹起的时候扬起一些灰尘。

在网页方面,当主要焦点出现的时候就可以开始执行次要动作,比如拖拽一个条目到列表中间。

.eight .shape.a {

transform: translateX(-6em);

animation: eight-shape-a 4s cubic-bezier(.57,-0.5,.43,1.53) infinite;

}

.eight .shape.b {

top: calc(50% + 6em);

opacity: 0;

animation: eight-shape-b 4s linear infinite;

}

.eight .shape.c {

transform: translateX(6em);

animation: eight-shape-c 4s cubic-bezier(.57,-0.5,.43,1.53) infinite;

}

@keyframes eight-shape-a {

0%, 50% {

transform: translateX(-5.5em);

}

70%, 100% {

transform: translateX(-10em);

}

}

@keyframes eight-shape-b {

0% {

transform: none;

}

20%, 30% {

transform: translateY(-1.5em);

opacity: 1;

animation-timing-function: cubic-bezier(.57,-0.5,.43,1.53);

}

32% {

transform: translateY(-1.25em);

opacity: 1;

}

34% {

transform: translateY(-1.75em);

opacity: 1;

}

36%, 38% {

transform: translateY(-1.25em);

opacity: 1;

}

42%, 60% {

transform: translateY(-1.5em);

opacity: 1;

}

75%, 100% {

transform: translateY(-8em);

opacity: 1;

}

}

@keyframes eight-shape-c {

0%, 50% {

transform: translateX(5.5em);

}

70%, 100% {

transform: translateX(10em);

}

}

.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);

}

九、时间节奏 (Timing)

动画的时间节奏是需要多久去完成,它可以被用来让看起来很重的对象做很重的动画,或者用在添加字符的动画中。

这在网页上可能只要简单调整 animation-duration 或 transition-duration 值。

这很容易让动画消耗更多时间,但调整时间节奏可以帮动画的内容和交互方式变得更出众。

.nine .shape.a {

animation: nine 4s infinite cubic-bezier(.93,0,.67,1.21);

left: calc(50% - 12em);

transform-origin: 100% 6em;

}

.nine .shape.b {

animation: nine 2s infinite cubic-bezier(1,-0.97,.23,1.84);

left: calc(50% + 2em);

transform-origin: 100% 100%;

}

@keyframes nine {

0%, 10% {

transform: translateX(0);

}

40%, 60% {

transform: rotateZ(90deg);

}

90%, 100% {

transform: translateX(0);

}

}

.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);

}

十、夸张手法 (Exaggeration)

夸张手法在漫画中是最常用来为某些动作刻画吸引力和增加戏剧性的,比如一只狼试图把自己的喉咙张得更开地去咬东西可能会表现出更恐怖或者幽默的效果。

在网页中,对象可以通过上下滑动去强调和刻画吸引力,比如在填充表单的时候生动部分会比收缩和变淡的部分更突出。

.ten .shape {

animation: ten 4s infinite linear;

transform-origin: 50% 8em;

top: calc(50% - 6em);

}

@keyframes ten {

0%, 10% {

transform: none;

animation-timing-function: cubic-bezier(.87,-1.05,.66,1.31);

}

40% {

transform: rotateZ(-45deg) scale(2);

animation-timing-function: cubic-bezier(.16,.54,0,1.38);

}

70%, 100% {

transform: rotateZ(360deg) scale(1);

}

}

.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);

}

十一、扎实的描绘 (Solid drawing)

当动画对象在三维中应该加倍注意确保它们遵循透视原则。因为人们习惯了生活在三维世界里,如果对象表现得与实际不符,会让它看起来很糟糕。

如今浏览器对三维变换的支持已经不错,这意味着我们可以在场景里旋转和放置三维对象,浏览器能自动控制它们的转换。

.eleven .shape {

background: none;

border: none;

perspective: 400px;

perspective-origin: center;

}

.eleven .shape .container {

animation: eleven 4s infinite cubic-bezier(.6,-0.44,.37,1.44);

transform-style: preserve-3d;

}

.eleven .shape span {

display: block;

position: absolute;

opacity: 1;

width: 4em;

height: 4em;

border: 1em solid #fff;

background: #2d97db;

}

.eleven .shape span.front {

transform: translateZ(3em);

}

.eleven .shape span.back {

transform: translateZ(-3em);

}

.eleven .shape span.left {

transform: rotateY(-90deg) translateZ(-3em);

}

.eleven .shape span.right {

transform: rotateY(-90deg) translateZ(3em);

}

.eleven .shape span.top {

transform: rotateX(-90deg) translateZ(-3em);

}

.eleven .shape span.bottom {

transform: rotateX(-90deg) translateZ(3em);

}

@keyframes eleven {

0% {

opacity: 0;

}

10%, 40% {

transform: none;

opacity: 1;

}

60%, 75% {

transform: rotateX(-20deg) rotateY(-45deg) translateY(4em);

animation-timing-function: cubic-bezier(1,-0.05,.43,-0.16);

opacity: 1;

}

100% {

transform: translateZ(-180em) translateX(20em);

opacity: 0;

}

}

.principle {

width: 100%;

height: 100vh;

position: relative;

}

小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Web前端开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频

如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注:前端)
img

总结

  • 框架原理真的深入某一部分具体的代码和实现方式时,要多注意到细节,不要只能写出一个框架。

  • 算法方面很薄弱的,最好多刷一刷,不然影响你的工资和成功率😯

  • 在投递简历之前,最好通过各种渠道找到公司内部的人,先提前了解业务,也可以帮助后期优秀 offer 的决策。

  • 要勇于说不,对于某些 offer 待遇不满意、业务不喜欢,应该相信自己,不要因为当下没有更好的 offer 而投降,一份工作短则一年长则 N 年,为了幸福生活要慎重选择!!!

    开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

0;

}

}

.principle {

width: 100%;

height: 100vh;

position: relative;

}

小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Web前端开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

[外链图片转存中…(img-rNOYj75F-1710589790291)]
[外链图片转存中…(img-zriM7eZZ-1710589790292)]
[外链图片转存中…(img-S5g0SgmV-1710589790292)]
[外链图片转存中…(img-gb6ClAwU-1710589790292)]

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频

如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注:前端)
[外链图片转存中…(img-myjTSAaA-1710589790293)]

总结

  • 框架原理真的深入某一部分具体的代码和实现方式时,要多注意到细节,不要只能写出一个框架。

  • 算法方面很薄弱的,最好多刷一刷,不然影响你的工资和成功率😯

  • 在投递简历之前,最好通过各种渠道找到公司内部的人,先提前了解业务,也可以帮助后期优秀 offer 的决策。

  • 要勇于说不,对于某些 offer 待遇不满意、业务不喜欢,应该相信自己,不要因为当下没有更好的 offer 而投降,一份工作短则一年长则 N 年,为了幸福生活要慎重选择!!!

    开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

喜欢这篇文章文章的小伙伴们点赞+转发支持,你们的支持是我最大的动力!

  • 20
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值