簡體   English   中英

加載后重新加載圖像(jquery / javascript)

[英]Reload image after it has loaded (jquery/javascript)

我想重新加載在服務器上不斷更新的圖像。 到目前為止,我只嘗試過:


setInterval(function(){
        if ($("#stream").data("loaded")) {
            $("#stream").attr("src", "http://keshira.com:8080/?action=snapshot&" + new Date().getTime());
        }
},100); 

<img id="stream" onload="$(this).data('loaded', 'loaded');" src="http://keshira.com:8080/?action=snapshot"/>

不幸的是,這也每100毫秒保持刷新圖像。 我的問題是我想盡可能快地加載新圖像。 因此,使用更長的時間間隔是沒有選擇的。 任何想法都非常感謝。

嘗試使用load事件有點不同:

$("#stream").on('load', function() {
    $("#stream").attr("src", "http://keshira.com:8080/?action=snapshot&" + new Date().getTime());
});

這是演示 我在那里使用setTimeout只是以某種方式限制它,但你可以刪除它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM