在我的jQuery文件上传器我有以下可用变量:uploadedBytes
,totalBytes
和timeStarted
。如何计算我上传的剩余时间?
如何使用这些变量计算上传剩余时间?我遇到了一个涉及uploadSpeed
变量的类似问题。
我可以从这些变量推导出uploadSpeed
吗?还是我能够仅使用这三个变量来计算剩余时间?
在我的jQuery文件上传器我有以下可用变量:uploadedBytes
,totalBytes
和timeStarted
。如何计算我上传的剩余时间?
如何使用这些变量计算上传剩余时间?我遇到了一个涉及uploadSpeed
变量的类似问题。
我可以从这些变量推导出uploadSpeed
吗?还是我能够仅使用这三个变量来计算剩余时间?
假设uploadedBytes
在上传过程中chaning。
- >当您知道上传开始时调用此脚本。
var timecontroller = setInterval(function(){
timeElapsed = (new Date()) - timeStarted; //assumng that timeStarted is a Data Object
uploadSpeed = uploadedBytes/(timeElapsed/1000); //upload speed in second
callback((totalBytes - uploadedBytes)/uploadSpeed); //callback is the funciont that show the time to usder the only argoment is the second remaining to the end
},1000)
- >当文件被完全上传清晰间隔timecontroller
:
clearInterval(timecontroller)
注意:timeStarted
必须是一个数据对象。
告诉我,如果它的工作。 thx to @Stefano Sanfilippo - 我使用他的一些脚本。
呃..上传时间取决于速度,所以你需要这个。您无法从您拥有的变量中进行计算。 – putvande
将取决于网络速度;如果你说“* x分钟基于2MB'线*” – MackieeE
@putvande的消息,则可以使用平均上传速度给出近似值。 –