美文网首页
New image 图片预加载问题

New image 图片预加载问题

作者: 新苡米 | 来源:发表于2021-07-20 10:07 被阅读0次

    创建一个Image对象:var a=new Image(); 定义Image对象的src: a.src=”xxx.gif”; 这样做就相当于给浏览器缓存了一张图片。

    图像对象:

    建立图像对象:图像对象名称=new Image([宽度],[高度])

    图像对象的属性: border complete height hspace lowsrc name src vspace width

    图像对象的事件:onabort onerror onkeydown onkeypress onkeyup onload

    代码:

        const img=new Image();  
        img.onload=function(){alert("img is loaded")};  
        img.onerror=function(){alert("error!")};  
        img.src="http://www.abaonet.com/img.gif";  
        function show(){alert("body is loaded");};  
        window.onload=show;
    

    相关文章

      网友评论

          本文标题:New image 图片预加载问题

          本文链接:https://www.haomeiwen.com/subject/pjqyultx.html