2012-02-04 165 views
1

我有這樣的:Plupload上傳進度速度

var uploader = $('#plupload').pluploadQueue(); 

uploader.bind('UploadProgress', function(up, file) 
{ 
    speedLog(uploader); 
}); 

function speedLog(uploader) { 
    var speed = uploader.total.bytesPerSec; 
    console.log(speed); 
}; 

和它的作品,我可以看到在Firebug的輸出,但大規模的,我的意圖是要提交「速度」低谷阿賈克斯。我想每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); 

看起來不錯:http://imageshack.us/photo/my-images/221/speedt.png/

回答

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);} 
} 
+0

希望能節省您的時間。 – 2012-02-07 05:15:44