mousemove:取得滑鼠頁面座標 e.pageX/Y,設定大圖 position:absolute 跟隨顯示。mouseout:隱藏大圖。$(function(){
var x = 5, y = 15; // 偏移量
$('table tr td img').mousemove(function(e){
$('#imageTip').attr('src', this.src)
.css({top: e.pageY + y, left: e.pageX + x})
.show();
}).mouseout(function(){
$('#imageTip').hide();
});
});
<table border="1">
<tr><th>選項</th><th>海報</th><th>名稱</th></tr>
<tr><td><input type="checkbox"></td><td><img src="images/xiao01.jpg"></td><td>楊冪</td></tr>
<tr><td><input type="checkbox"></td><td><img src="images/xiao02.jpg"></td><td>林蕭</td></tr>
</table>
<img id="imageTip" class="clsImg" src="images/xiao01.jpg" alt="">
table tr td img { width: 240px; height: 240px; border: solid 1px #666; cursor: pointer; }
.clsImg { position: absolute; width: 400px; height: 400px; border: 1px solid #ccc; display: none; z-index: 999; }
上述為「顯示大圖」,若需「放大鏡區域跟隨滑鼠顯示原圖對應區域」,請使用成熟套件:
alt 說明。tabindex="0" + keydown)。