HTML5 Canvas replace to <div>

六月ゝ 毕业季﹏ 提交于 2020-01-06 13:58:18

问题


I'm trying replace HTML5 Canvas to simple <div> But I don't know how to replace this line:

ctx.drawImage(tileImg[drawTile],xpos,ypos);

Maybe anyone have idea how to replace this into <div>?

example : http://jsfiddle.net/HDpMW/5/ (this code from glacialflame.com)


回答1:


Use <img> elements, and append them dynamically like this: http://jsfiddle.net/HDpMW/6/

var elem = document.createElement('img');
elem.src = tileDict[drawTile];
elem.style.position = 'absolute';
elem.style.left = xpos + 'px';
elem.style.top = ypos + 'px';
ctx.appendChild(elem);


来源:https://stackoverflow.com/questions/6266456/html5-canvas-replace-to-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!