【发布时间】:2017-09-28 23:16:25
【问题描述】:
我正在尝试在加载的图像上绘制一些东西。但是,由于某种原因,画布出现在图像下方而不是顶部。我这样做如下:
我有以下容器:
<div id="container">
<img src="{{url_for('static', filename='nature.jpg')}}" id="target" style="zIndex=1">
</div>>
我正在尝试按如下方式添加画布:
window.onload = function() {
var img = document.getElementById('target');
var width = img.naturalWidth;
var height = img.naturalHeight;
var canvas = document.createElement('canvas'); //Create a canvas element
//Set canvas width/height
canvas.style.width=width;
canvas.id = 'mycanvas';
canvas.style.height=height;
//Set canvas drawing area width/height
canvas.width = width;
canvas.height = height;
//Position canvas
canvas.style.position='absolute';
canvas.style.left=0;
canvas.style.top=0;
canvas.style.zIndex=100000;
canvas.style.pointerEvents='none'; //Make sure you can click 'through' the canvas
$('#container').append(canvas);
}
但是,画布出现在图像下方而不是在图像上方。我做错了什么?
谢谢
【问题讨论】:
-
你能分享一下jsfiddle吗?
标签: javascript html image canvas