tim*_*imo 0 javascript upload jquery
在我的jQuery 文件上传器中,我有以下可用变量:uploadedBytes,totalBytes和timeStarted.
如何使用这些变量计算上传的剩余时间?我遇到了一个涉及uploadSpeed变量的类似问题。
我可以uploadSpeed从这些变量中推断出吗?或者我能否仅使用这三个变量来计算剩余时间?
假设uploadedBytes在上传过程中发生变化。
-> 当您知道上传开始时调用此脚本:
var timecontroller = setInterval(function(){
timeElapsed = (new Date()) - timeStarted; // Assuming that timeStarted is a Date Object
uploadSpeed = uploadedBytes / (timeElapsed/1000); // Upload speed in second
// `callback` is the function that shows the time to user.
// The only argument is the number of remaining seconds.
callback((totalBytes - uploadedBytes) / uploadSpeed);
}, 1000)
Run Code Online (Sandbox Code Playgroud)
-> 文件完全上传后,清除间隔timecontroller:
clearInterval(timecontroller)
Run Code Online (Sandbox Code Playgroud)
注意timeStarted必须是 Date 对象。
告诉我它是否有效。感谢@Stefano Sanfilippo - 我使用了他的一些脚本。
| 归档时间: |
|
| 查看次数: |
5682 次 |
| 最近记录: |