简体   繁体   English

如何获取具有使用easyOutSine进行CSS过渡的元素需要覆盖一定距离的时间?

[英]How to get the time an element that has CSS transition with easeOutSine needs to cover a certain distance?

Ok, this is one for math people, I guess. 好的,我想这是数学人士的选择。 I have some basic knowledge of ease functions but need some helping hand with this. 我对缓动功能有一些基本的了解,但需要一些帮助。

I have an element that is translated with CSS transition (translateX) using 'easeOutSine' function. 我有一个使用'easeOutSine'函数通过CSS转换(translateX)翻译的元素。

It covers distance A in 1500 ms. 它在1500毫秒内覆盖了距离A。 I need to find out how much time it needs to cover a distance B (somewhere in between) 我需要找出需要多少时间才能覆盖距离B(介于两者之间的某个位置)

The function for 'easeOutSine' is: “ easeOutSine”的功能是:

function easeOutSine(t, b, c, d) {
    return c * Math.sin(t/d * (Math.PI/2)) + b;
}

Obviously A and B are known values for me. 显然,A和B是我的已知值。 But I need to know where to put them in the arguments or how to handle this at all. 但是我需要知道将它们放在参数中的位置或如何处理。 Thanks very much in advance! 首先十分感谢!

EDIT: 编辑:

Example: Let's say the element moves 1000px in those 1500ms. 示例:假设元素在那1500毫秒内移动了1000像素。 How much time has exactly passed when it is at 360px? 在360px分辨率下,到底经过了多少时间? It is simple to find out when it moves linear but I can't get ahead of this with the easeOutSine function. 很容易找出线性运动的时间,但是使用easyOutSine函数无法超越它。 (When it reaches this position I'd like to attach a class to another element) (当到达这个位置时,我想将一个类附加到另一个元素上)

Assumptions 假设条件

What I'm hearing is that if you were to trace the line y = c * sin(t/d*pi/2) + b on a piece of paper from t=0 to t=1500, the distance traveled by your pencil would be A. Your goal is to find the t such that the distance is B. 我听到的是,如果要在一张纸上从t = 0到t = 1500描画y = c * sin(t / d * pi / 2)+ b线,则铅笔移动的距离将是A。您的目标是找到距离为B的t。

Solution

Long story short, you're gonna be looking at the arc length formula . 长话短说,您将要研究弧长公式 Specifically, you're going to need to solve B = integral from 0 to t of sqrt(1+(pi*c/(2d))^2 * cos(pi*t/(2*d))^2)dt, where B, c, and d are constants and the variable you're looking for is B. 具体来说,您需要求解B =从sqrt的0到t的整数(1+(pi * c /(2d))^ 2 * cos(pi * t /(2 * d))^ 2)dt ,其中B,c和d是常量,而您要查找的变量是B。

It's not really obvious to me how the information you have about A can help you solve this, so I would recommend a binary search for t where your initial range is from [0, 1500] and you 'evaluate' the function (that integral) via some technique for approximating integrals. 对我来说,并不是很明显,关于A的信息如何帮助您解决这个问题,所以我建议对t进行二进制搜索,其中初始范围是[0,1500],然后您“评估”函数(该整数)通过一些近似积分的技术 The function y = integral from 0 to t of sqrt(1+(pi*c/(2d))^2 * cos(pi*t/(2*d))^2)dt is monotonic over t, so that would get you the correct answer. 函数y = sqrt(1+(pi * c /(2d))^ 2 * cos(pi * t /(2 * d))^ 2)dt从0到t的积分在t上是单调的,因此得到正确答案。

Sorry about how mathy that got; 不好意思那算是什么了; what you're looking to do isn't really possible to calculate explicitly. 您要执行的操作实际上无法显式计算。 You might want to check out some tutorial on how to binary search an answer to a math problem if you're not familiar with that method. 如果您不熟悉该方法,则可能需要查看一些有关如何对数学问题的答案进行二进制搜索的教程。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM