javascript编写的购物网站的商品图片放大程序

来源:岁月联盟 编辑:exp 时间:2012-03-17

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
        <title>Insert title here</title>
  <script style="text/javascript">

   //商城 购物网,图片放大程序
   window.onload = function(){
    var sImg = document.getElementById("sImg");
    var bImg = document.getElementById("bImg");
    var div = document.getElementById("div");
   
    sImg.onmousemove = function(){
     var xMove = event.x - 8;
     var yMove = event.y - 8;
    
     bImg.style.marginLeft = -xMove * 2;
     bImg.style.marginTop = -yMove * 2;
    }
    sImg.onmouseenter = function(){
     div.style.display = "block";
    }
    sImg.onmouseleave = function(){
     div.style.display = "none";  //为什么不直接些none?
    }
   }
  </script>
    </head>
    <body>
     <img src="../img/beau.jpg" style="width:50px; height:70px" id="sImg"> 
  <!--为什么要放到div中?-->
     <div style="border:1px solid; width:100px; height:140px; position:absolute; left:58px; top:78px; overflow:hidden;display:none" id="div">
  <img src="../img/beau.jpg" id="bImg">
     </div>
    </body>
</html>


 

摘自  代俊建的专栏