如何计算上传的剩余时间?

问题描述 投票:0回答:1

在我的jQuery文件上传器中,我有以下可用变量:uploadedBytestotalBytestimeStarted

如何使用这些变量计算上传剩余时间?我遇到了一个涉及uploadSpeed变量的类似问题。

我可以从这些变量中推断出uploadSpeed吗?或者我能够仅使用这三个变量计算剩余时间吗?

javascript jquery upload
1个回答
4
投票

假设在上传期间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到@Stefano Sanfilippo - 我用他的一些剧本。

© www.soinside.com 2019 - 2024. All rights reserved.