how to show image only when it is completely loaded?

后端 未结 2 1949
暗喜
暗喜 2020-12-06 20:09

I have an img tag on my web page. I give it the url for an IP camera from where it get images and display them. I want to show image when it is completely loaded. so that I

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 20:22

    Preload the image and replace the source of the after the image has finished loading.

    function LoadImage() {
        var img = new Image(),
            x = document.getElementById("stream");
    
        img.onload = function() {
            x.src = img.src;
        };
    
        img.src = "http://IP:PORT/jpg/image.jpg" + "?_=" + (+new Date());
    }
    

提交回复
热议问题