MooTools - 如何重新加载图片?

时间:2011-06-22 11:16:01

标签: image camera mootools reload

有没有办法使用mootools重新加载相同的图像。我有一个相机给我图像,但我必须刷新它。我写了这个,但它不能很好地运作:

var url = "some valid url to some image.jpg";
var timer = 10; 
var periodical;

var camera_container;
var refresh = (function() {
    var loader = new Asset.image(url, {
        onLoad : function() {
            camera_container.empty();
            camera_container.inject(loader);
        }
    });
});

window.addEvent('domready', function() {
    // the periodical starts here, the * 1000 is because milliseconds required
    refresh.periodical(timer * 1000, this); 
    camera_container = $('camera-image');
});

任何帮助表示赞赏。感谢。

2 个答案:

答案 0 :(得分:0)

为什么不在网址上添加种子位?

(function() {
    var url = "some valid url to some image.jpg?";
    this.timer = 10;
    var counter = 0;

    this.refresh = (function() {
        var loader = new Asset.image(url + counter, {
            onLoad: function() {
                camera_container.empty();
                camera_container.inject(loader);
                counter++;
            }
        });
    });

})();

window.addEvent('domready', function() {
    // the periodical starts here, the * 1000 is because milliseconds required
    refresh.periodical(timer * 1000, this);
    this.camera_container = $('camera-image');
});

这样,url将始终是path / image.jpg?n,其中n发生变化,并强制浏览器重新获取它。

答案 1 :(得分:0)

我认为这样的事情也可以起作用:

<div id="image-holder">
    <img src="http://www.image.com/image.jpg"/>
</div>


var srcImage   = 'http://www.image.com/image.jpg';
var reloadTime = 4000;
var holder = document.id('image-holder');

var imageReload = function(){
    holder.empty();
    var newImage =  new Element('img',{
            id:'image',
            src:srcImage ,
            alt:'image new'
        }).inject(holder);    
}

var start = function() {
    interval = imageReload.periodical(reloadTime);
};

start();