[js]为什么画布里不出现图片呢?在线等

<body>

    <div id="main"></div>

</div>

<script type="text/javascript">

function GED(ele) {return document.getElementById(ele);}

function load_source(url, w, h) {

    this.canvas = document.createElement('canvas');

    this.canvas.width = w;

    this.canvas.height = h;

    this.ctx = this.canvas.getContext('2d');

    this.img = new Image();

    this.img.src = url;

    this.img.onload = function () {

        this.ctx.drawImage(this.img, 0, 0);

    }.bind(this);

    return this.canvas;

}

source = new load_source('http://htmljs.b0.upaiyun.com/uploads/1382542991440-2angles.png', 300, 100);

canvas = document.createElement('canvas')

canvas.id = 'ff'

canvas.width = 300;

canvas.height = 100;

GED('main').appendChild(canvas);

ctxs = GED('ff').getContext('2d'); 

ctxs.drawImage(source, 110, 110);

</script>


浮云间
浏览 607回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript