【发布时间】:2018-06-22 08:20:18
【问题描述】:
我正在使用自定义计时功能 (http://cubic-bezier.com/#1,0,1,1) 淡入 div(使用 CSS 转换)。计时功能基本上是“ease-in”的一个更极端的版本。
div {
opacity: 0;
transition: opacity 1s;
.in {
opacity: 1;
transition-timing-function: cubic-bezier(1, 0, 1, 1);
}
除此之外,我希望能够通过在屏幕上滑动来淡入 div。我正在使用以下 Jquery 根据用户滑动的距离来设置不透明度:
documentWidth = $(document).width();
$(document).on('touchmove', function(e) {
// How much of the animation is completed (in %)
completion = e.changedTouches[0].pageX / documentWidth;
$('div').css('opacity', completion);
})
不,这是线性的!有没有聪明的数学家可以弄清楚如何重新陈述最后一行来表示我的计时函数?
因此,例如,如果completion 为 25%,则不透明度应为 2% 左右。在 50% 时,应该在 11% 左右,在 75% 时应该在 31% 左右。
【问题讨论】:
-
您为什么不使用
animation而不是transition,然后在其中相应地定义您的参数。
标签: css animation math transition timing