我有这个:
var uploader = $('#plupload').pluploadQueue();
uploader.bind('UploadProgress', function(up, file)
{
speedLog(uploader);
});
function speedLog(uploader) {
var speed = uploader.total.bytesPerSec;
console.log(speed);
};
它有效,我可以看到萤火虫的输出,但是很大,我的意图是通过ajax提交“速度”。我希望每隔5秒左右调用一次speedLog(),我该怎么做呢?
谢谢SR查询。 我这样做了:
window.setInterval(
function speedLog(uploader) {
var uploader = $('#plupload').pluploadQueue();
var speed = uploader.total.bytesPerSec;
if(speed > 0)
{
console.log(speed);
} else {
clearInterval(ib);
}
}, 5000);
答案 0 :(得分:1)
尝试使用jquery进度条插件..你不喜欢插件以另一种方式尝试这种逻辑。
var ib;
var timer_speed = 200; // 1000 = 1 second
function progressBar_completeHandler(event, ui) {
// what you want to do after completing the progress. do it here
}
$(function() {
$("#progressbar").progressbar({value:0, complete:progressBar_completeHandler});
});
function start_timer(){
val = $("#progressbar").progressbar("option", "value");
ib=setInterval("increment_bar()",timer_speed);
}
function increment_bar() {
$('#progressbar' ).progressbar( 'option', 'value', val+=1);
if(val > 99){clearInterval(ib);}
}