你想達到什麼樣的效果 - 你的問題只是暗示在鼠標結束時顯示某種圖像#視頻選擇?
操作DOM很慢。
,而不是...
爲boxImage
快速繪製創建覆蓋你#視頻選擇一個canvas元素:
然後收聽鼠標懸停/鼠標移開事件來顯示覆蓋畫布上boxImage
:
// 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不幸的是:( –