这里要注意下:
1. 对象.style.left,值带像素,比如div1.style.left="10px";
2. 放大图的层没有在鼠标附近是由于position属性的问题,设置为绝对后就可以应用X,Y轴的坐标
=========================================================
源码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>ex6</title>
<style type="text/css">
td{
border:1px black solid;
text-align:center;
}
img{
width:100;
height:80;
}
#imgBig{
width:400;
height:300;
z-index:10;
}
.hide{
display:none;
}
.show{
display:block;
}
</style>
<script type="text/javascript">
function move(event,imgB){
var x = event.clientX+"px";
var y = event.clientY+"px";
var divB = document.getElementByIdx_x("bigImg");
document.getElementByIdx_x("imgBig").setAttribute("src",imgB)
divB.className="show";
divB.style.position="absolute";
divB.style.left = x;
divB.style.top = y;
}
function out(){
var divB = document.getElementByIdx_x("bigImg");
divB.className="hide";
}
function divOver(){
var divB = document.getElementByIdx_x("bigImg");
divB.className="show";
//javascript:document.getElementByIdx_x('bigImg').className='show'
}
</script>
</head>
<body>
<table cellspacing="0" cellpadding="0" width="800">
<tr>
<td>商品图片</td>
<td>商品名称</td>
<td>商品价格</td>
</tr>
<tr>
<td><img src="ex6_1.jpg" name="products" οnmοusemοve="move(event,'ex6_1_b.jpg')" οnmοuseοut="out()"/></td>
<td>HIS 6870 H687QNT1G2M</td>
<td>¥1699.00</td>
</tr>
<tr>
<td><img src="ex6_2.jpg" name="products" οnmοusemοve="move(event,'ex6_2_b.jpg')" οnmοuseοut="out()" /></td>
<td>夏普 LCD-32LX330A 32英寸LED液晶电视</td>
<td>¥3599.00</td>
</tr>
<tr>
<td><img src="ex6_3.jpg" name="products" οnmοusemοve="move(event,'ex6_3_b.jpg')" οnmοuseοut="out()" /></td>
<td>Canon 佳能 EOS 5D Mark II</td>
<td>¥19999.00</td>
</tr>
<tr>
<td><img src="ex6_4.jpg" name="products" οnmοusemοve="move(event,'ex6_4_b.jpg')" οnmοuseοut="out()" /></td>
<td>>飞利浦 劲锋系列 PT720 剃须刀</td>
<td>¥749.00</td>
</tr>
</table>
<div id="bigImg" class="hide">
<img src="" id="imgBig" οnmοuseοver="divOver()" οnmοuseοut="out()" />
</div>
//以下2段待修正
<!-- <script type="text/javascript">
var prodcuts = document.getElementsByName("products");
for(var i=0;i<products.length;i++){
products[i].οnmοuseοver=function(event){
var x = event.clientX;
var y = event.clientY;
alert(x+":"+y);
}
}
</script> -->
<!-- <script type="text/javascript">
var products = document.getElementsByName("products");
for(var i=0;i<products.length;i++){
products[i].οnmοuseοver="move(this.event)";
}
function move(event){
var x = event.clientX;
var y = event.clientY;
alert(x+":"+y);
} -->
</script>
</body>
</html>