码迷,mamicode.com
首页 > Web开发 > 详细

html5 image使用大全

时间:2017-04-04 23:53:57      阅读:1253      评论:0      收藏:0      [点我收藏+]

标签:html5   image   

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset = utf-8">
</head>
<script type="text/javascript" charset="utf-8">
    var imageLoader = {
        loaded:true,
        loadedImages:0,
        totalImages:0,
        load:function(url){
            this.totalImages++;
            this.loaded = false;
            var image = new Image();
            image.src = url;
            image.onload = function(){//图片加载后调用的图片
                imageLoader.loadedImages++;
                if(imageLoader.loadedImages === imageLoader.totalImages){
                    imageLoader.loaded = true;
                }
            }
            return image;
        }
    };

    function pageLoaded(){
        var canvas = document.getElementById(‘testcanvas‘);//得到画布
        var context = canvas.getContext(‘2d‘);//得到绘图环境  参数为绘图环境的类型

        imageLoader.loaded = false;
        var image_gx1 = imageLoader.load(‘/testimg/gx/gx1.png‘);
        var image_gx2 = imageLoader.load(‘/testimg/gx/gx2.jpg‘);
        var image_gx3 = imageLoader.load(‘/testimg/gx/gx3.jpg‘);
        var image_gx4 = imageLoader.load(‘/testimg/gx/gx4.jpg‘);



        var interHandler = setInterval(function () {
            if(imageLoader.loaded){
                context.drawImage(image_gx1,0,0,100,100);
                context.drawImage(image_gx2,101,0,100,100);
                context.drawImage(image_gx3,201,0,100,100);
                context.drawImage(image_gx4,301,0,100,100);
                clearInterval(interHandler)
            }
        },50);
    }
</script>
<body onload="pageLoaded();">
<canvas width="1200" height="480" id="testcanvas" style="border: black 1px solid">
</canvas>
</body>
</html>


html5 image使用大全

标签:html5   image   

原文地址:http://quietnight.blog.51cto.com/7163892/1912913

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!