-2
私は、読み込まれた画像の上にいくつかのものを描画しようとしています。しかし、なんらかの理由でキャンバスが上にない画像の下に表示されます。次のように私はそれをやっている:画像の上にキャンバスを配置できません
を私は次のコンテナいる:
<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);
}
しかし、キャンバスが下に表示されますイメージの上にではなくむしろイメージ。私は間違って何をしていますか?
あなたはインラインスタイルstyle="zIndex=1"
の間違った構文を使用していたおかげで
あなたはjsfiddleを共有することができ、位置を必要としますか? –
ここをクリックしてください:http://stackoverflow.com/questions/12661124/how-to-apply-hovering-on-html-area-tag/12667751#12667751 – enhzflep