あなたは何を達成しようとしていますか?あなたの質問はマウスがビデオ選択よりも上になったときに何らかの画像を表示することを示唆していますか?
DOMの操作が遅いです。
代わりに...
はboxImage
の速い描画のためのあなたの#ビデオ選択をカバーするcanvas要素を作成します。
- #canvas要素を作成します。
- #video-selectionを両方ともラップします。& #canvas in div #wrapper。
CSSを使用して#canvasで#video-selectionをカバーします。
は次にカバーキャンバス上boxImage
表示するマウスオーバー/マウスアウトイベントをリッスン
<div id=wrapper width=320 height=240>
<div id='video-selection' width=320 height=240></div>
<canvas id=canvas width=320 height=240></canvas>
</div>
#wrapper{position:relative;}
#video-selection, #canvas{position:absolute;}
:
// canvas related vars
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
var cw=canvas.width;
var ch=canvas.height;
// set where boxImage will be drawn on the canvas
var boxX=20;
var boxY=30;
// on mouseout, clear boxImage off the canvas
$("#video-section").mouseout(function(){
context.clearRect(0,0,cw,ch);
});
// on mouseover, draw boxImage on the canvas
$("#video-section").mouseover(function(){
context.drawImage(boxImage,boxX,boxY);
});
イメージオブジェクトを使用してイメージをキャッシュできます。イメージが大きければ、イメージsrcを毎回変更するのが遅くなることがあります。 – modernator
これで作業のスニペットやフィドルを作成できますか? – vijayP
@vijayP残念ながらいいえ:( –