今天前端笔试遇到了一个题考察动画animate-timing-function属性的cubic-bezier() 函数,比较贝塞尔曲线的快慢。 :cubic-bezier(1.23,.97,.89,.22) D. animation-timing-function :cubic-bezier(.22,.97,.89,1.23) 解析: A.k1 ②cubic-bezier() 函数 cubic-bezier() 函数定义了一个贝塞尔曲线(Cubic Bezier)。 cubic-bezier() 可用于 animation-timing-function 和 transition-timing-function 属性。 语法:cubic-bezier(x1,y1,x2,y2) https://www.runoob.com/cssref/func-cubic-bezier.html ③贝塞尔曲线的快慢 cubic-bezier
: all 500ms cubic-bezier(0.000, 0.995, 0.990, 1.000); -o-transition: all 500ms cubic-bezier(0.000, 0.995 : all 500ms cubic-bezier(0.000, 0.995, 0.990, 1.000); -o-transition: all 500ms cubic-bezier(0.000, 0.995 : all 500ms cubic-bezier(0.000, 0.995, 0.990, 1.000); -ms-transition: all 500ms cubic-bezier(0.000, 0.995 : all 800ms cubic-bezier(0.000, 0.995, 0.990, 1.000); -o-transition: all 800ms cubic-bezier(0.000, 0.995 : all 500ms cubic-bezier(0.000, 0.995, 0.990, 1.000); -o-transition: all 500ms cubic-bezier(0.000, 0.995
linear 规定以相同速度开始至结束的过渡效果(等于 cubic-bezier(0,0,1,1))。 ease 规定慢速开始,然后变快,然后慢速结束的过渡效果(cubic-bezier(0.25,0.1,0.25,1))。 ease-in 规定以慢速开始的过渡效果(等于 cubic-bezier(0.42,0,1,1))。 ease-out 规定以慢速结束的过渡效果(等于 cubic-bezier(0,0,0.58,1))。 cubic-bezier(n,n,n,n) 在 cubic-bezier 函数中定义自己的值。可能的值是 0 至 1 之间的数值。
important; -ms-transition: all 0.2s cubic-bezier(0, 0.34, 0.71, 1.26) ! important; -o-transition: all 0.2s cubic-bezier(0, 0.34, 0.71, 1.26) ! important; transition: all 0.2s cubic-bezier(0, 0.34, 0.71, 1.26) ! important; -o-transition: all 0.2s cubic-bezier(0, 0.34, 0.71, 1.26) ! important; transition: all 0.2s cubic-bezier(0, 0.34, 0.71, 1.26) !
ease:规定慢速开始,然后变快,然后慢速结束的过渡效果(cubic-bezier(0.25,0.1,0.25,1))。 ease-in:规定以慢速开始的过渡效果(等于cubic-bezier(0.42,0,1,1))。 ease-out:规定以慢速结束的过渡效果(等于cubic-bezier(0,0,0.58,1))。 cubic-bezier(n,n,n,n):在cubic-bezier函数中定义自己的值。可能的值是0至1之间的数值。 ">cubic-bezier
(.19,1,.7,1); } 25% { transform: translateY(-4em); animation-timing-function: cubic-bezier (.19,1,.7,1); } 40% { transform: translateY(0em); animation-timing-function: cubic-bezier (.19,1,.7,1); } 50% { transform: translateY(3em); animation-timing-function: cubic-bezier (.19,1,.7,1); } 60% { transform: translateY(6em); animation-timing-function: cubic-bezier (.19,1,.7,1); } 66% { transform: translateY(7.5em); animation-timing-function: cubic-bezier
我们还将看一下CSS3 Cubic-Bezier(贝塞尔)曲线,它是 CSS 过渡,为弹出框提供了更加流畅的运动,而不是僵化的机械运动。 这是我们最后的效果: ? 让我们开始吧! -moz-transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55); transition: all 0.5s cubic-bezier 这就是 CSS 中 Cubic-Bezier 点的含义。由于动画短,所以动作很细微。弹出框从正方形底部开始时缓慢开始,然后开始加速到顶部。 尽管您可以创建没有 Cubic-Bezier 曲线过渡的动画,但动画的差异如下: 有 Cubic-Bezier 曲线过渡的动画 ? 没有 Cubic-Bezier 曲线过渡的动画 ? 在 CSS3 Cubic-Bezier 塞尔曲线的帮助下,动画流畅且令人愉悦。 这类知识非常有用,可以作为你显示社交媒体帐户的网站设计的一部分。
rotate(0deg); } /*动画结束最后一帧*/ to { transform: rotate(360deg); } } .box1{ /*动画:2.4s执行完毕,cubic-bezier 贝塞尔曲线(先快后慢)*/ animation: trotate 2.4s cubic-bezier(.23,1.02,.44,.9); } ? (.23,1.02,.44,.9); z-index: 4; } .box2{ /* 2s完成 */ animation: trotate 2.2s cubic-bezier(.23,1.02 (.23,1.02,.44,.9); animation-delay: 1.2s; z-index: 2; } .box4{ animation: trotate 1.8s cubic-bezier (.23,1.02,.44,.9); animation-delay: 1.8s; z-index: 1; } .box5{ animation: trotate 1.6s cubic-bezier
(0, 0, 0.25, 1); } #div2 { animation-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1) ; } #div3 { animation-timing-function: cubic-bezier(0.42, 0, 1, 1); } #div4 { : cubic-bezier(0, 0, 1, 1); } #div2 { -webkit-animation-timing-function: cubic-bezier( 0.25, 0.1, 0.25, 1); } #div3 { -webkit-animation-timing-function: cubic-bezier(0.42, 0 , 1, 1); } #div4 { -webkit-animation-timing-function: cubic-bezier(0, 0, 0.58, 1);
(n,n,n,n); //默认值是ease 值描述linear规定以相同速度开始至结束的过渡效果(等于 cubic-bezier(0,0,1,1))。 ease规定慢速开始,然后变快,然后慢速结束的过渡效果(cubic-bezier(0.25,0.1,0.25,1))。 ease-in规定以慢速开始的过渡效果(等于 cubic-bezier(0.42,0,1,1))。ease-out规定以慢速结束的过渡效果(等于 cubic-bezier(0,0,0.58,1))。 ease-in-out规定以慢速开始和结束的过渡效果(等于 cubic-bezier(0.42,0,0.58,1))。 cubic-bezier(n,n,n,n)在 cubic-bezier 函数中定义自己的值。可能的值是 0 至 1 之间的数值。
(n,n,n,n); //默认值是ease 值描述linear规定以相同速度开始至结束的过渡效果(等于 cubic-bezier(0,0,1,1))。 ease规定慢速开始,然后变快,然后慢速结束的过渡效果(cubic-bezier(0.25,0.1,0.25,1))。 ease-in规定以慢速开始的过渡效果(等于 cubic-bezier(0.42,0,1,1))。ease-out规定以慢速结束的过渡效果(等于 cubic-bezier(0,0,0.58,1))。 ease-in-out规定以慢速开始和结束的过渡效果(等于 cubic-bezier(0.42,0,0.58,1))。 cubic-bezier(n,n,n,n)在 cubic-bezier 函数中定义自己的值。可能的值是 0 至 1 之间的数值。
其实所有的这五种曲线都是通过(三次)贝塞尔曲线来指定的,而CSS的调速函数都是只有一个片段的贝塞尔曲线,每个函数也只有两个控制锚点,CSS就提供了一个cubic-bezier()函数,允许我们指定自定义调速函数 举例来说,ease等同于cubic-bezier(.25,.1,.25,1),因此它的反向版本就是cubic-bezier(.1,.25,1,.25) @keyframes bounce{ 60% 这里我们就用到了上面说起的调速函数cubic-bezier(),在这个例子中,我们希望调速函数先到达110%的程度(相当于scale(1.1)),然后在过渡回100%,我们把控制锚点向上移, [cubic-bezier (.25,.1,.3,1.5); } [cubic-bezier(.25,.1,.3,1.5)] but,wait...当提示框收缩时,左下角出现的是什么? ,发现已经关闭提示框已经恢复到我们设置cubic-bezier()之前的样子了, 但是其实我们仔细观察发现另一个问题:提示框的关闭动作明显要迟钝一些。
(0.63, 0.15, 0.49, 0.93); animation: body-movement 1s infinite cubic-bezier(0.63, 0.15, 0.49 (0.63, 0.15, 0.49, 0.93); animation: tail-movement 1s infinite cubic-bezier(0.63, 0.15, 0.49 (0.63, 0.15, 0.49, 0.93); animation: eyebrows-movement 1s infinite cubic-bezier(0.63, 0.15, (0.63, 0.15, 0.49, 0.93) 0s; animation: leg-animation 2s infinite cubic-bezier(0.63, 0.15, (0.63, 0.15, 0.49, 0.93) 0s; animation: foot-shadow-animation 2s infinite cubic-bezier(0.63
其实所有的这五种曲线都是通过(三次)贝塞尔曲线来指定的,而CSS的调速函数都是只有一个片段的贝塞尔曲线,每个函数也只有两个控制锚点,CSS就提供了一个cubic-bezier()函数,允许我们指定自定义调速函数 举例来说,ease等同于cubic-bezier(.25,.1,.25,1),因此它的反向版本就是cubic-bezier(.1,.25,1,.25) @keyframes bounce{ 60% 这里我们就用到了上面说起的调速函数cubic-bezier(),在这个例子中,我们希望调速函数先到达110%的程度(相当于scale(1.1)),然后在过渡回100%,我们把控制锚点向上移, ? */ } .callout{ transform-origin:1.4em -.4em; transition:.5s cubic-bezier(.25,.1,.3,1.5); } 再试一试 ,发现已经关闭提示框已经恢复到我们设置cubic-bezier()之前的样子了, 但是其实我们仔细观察发现另一个问题:提示框的关闭动作明显要迟钝一些。
(n,n,n,n); 值 描述 linear 规定以相同速度开始至结束的过渡效果(等于 cubic-bezier(0,0,1,1))。 ease (逐渐变慢),规定慢速开始,然后变快,然后慢速结束的过渡效果(cubic-bezier(0.25,0.1,0.25,1))。 ease-in (加速),规定以慢速开始的过渡效果(等于 cubic-bezier(0.42,0,1,1))。 ease-out (减速),规定以慢速结束的过渡效果(等于 cubic-bezier(0,0,0.58,1))。 cubic-bezier(n,n,n,n) (该值允许你去自定义一个时间曲线),在 cubic-bezier 函数中定义自己的值。可能的值是 0 至 1 之间的数值。
0); mix-blend-mode: lighten;}.red { background: #FA167C; -webkit-animation: attract-orange 700ms cubic-bezier (0.3, 0.5, 0.4, 0.9) infinite alternate-reverse; animation: attract-orange 700ms cubic-bezier(0.3, 0.5 0.9) infinite alternate-reverse;}.blue { background: #0A0BF5; -webkit-animation: attract-blue 700ms cubic-bezier (0.3, 0.5, 0.4, 0.9) infinite alternate-reverse; animation: attract-blue 700ms cubic-bezier(0.3, 0.5
ease 规定慢速开始,然后变快,然后慢速结束的过渡效果(cubic-bezier(0.25,0.1,0.25,1))。 ease-in 规定以慢速开始的过渡效果(等于 cubic-bezier(0.42,0,1,1))。 ease-out 规定以慢速结束的过渡效果(等于 cubic-bezier(0,0,0.58,1))。 ease-in-out 规定以慢速开始和结束的过渡效果(等于 cubic-bezier(0.42,0,0.58,1))。 cubic-bezier(n,n,n,n) 在 cubic-bezier 函数中定义自己的值。可能的值是 0 至 1 之间的数值。
(0.4, 0.2, 0.2, 1) transition -webkit-transform .7s cubic-bezier(0.4, 0.2, 0.2, 1) -o-transition transform .7s cubic-bezier(0.4, 0.2, 0.2, 1) transition transform .7s cubic-bezier(0.4, 0.2, 0.2, 1 ) transition transform .7s cubic-bezier(0.4, 0.2, 0.2, 1), -webkit-transform .7s cubic-bezier(0.4, transform .7s cubic-bezier(0.4, 0.2, 0.2, 1) transition transform .7s cubic-bezier(0.4, 0.2, 0.2, 1 ) transition transform .7s cubic-bezier(0.4, 0.2, 0.2, 1), -webkit-transform .7s cubic-bezier(0.4,
webkit-transform-origin: var(--x) 50%; transform-origin: var(--x) 50%; transition: -webkit-transform 0.3s cubic-bezier (0.535, 0.05, 0.355, 1); transition: transform 0.3s cubic-bezier(0.535, 0.05, 0.355, 1); transition : transform 0.3s cubic-bezier(0.535, 0.05, 0.355, 1), -webkit-transform 0.3s cubic-bezier(0.535, 0.05
100%; left: 0; width: 100%; height: 2px; background: #3498db; transform: scaleX(0); transition: 0.4s cubic-bezier webkit-transform-origin: var(–x) 50%; transform-origin: var(–x) 50%; transition: -webkit-transform 0.3s cubic-bezier (0.535, 0.05, 0.355, 1); transition: transform 0.3s cubic-bezier(0.535, 0.05, 0.355, 1); transition: transform 0.3s cubic-bezier(0.535, 0.05, 0.355, 1), -webkit-transform 0.3s cubic-bezier(0.535, 0.05,