javascipt与div实现的图片拖动功能

<html>
 <head>
  <script language=javascript>
   function imgMove()
   {
    //if the left button was not pressed,return
    if(window.event.button!= 1) 
    {
       return 0;
    }
    //get the new position
    with(window.event.srcElement.style)
    {
        pixelLeft = window.event.x-236/2-document.all.imgDiv.offsetLeft;
        pixelTop = window.event.y-118/2-document.all.imgDiv.offsetTop;
    }
    window.event.returnValue=false;
   }
  </script>
 </head>
 <body>
   <div Style="position:relative" ID="imgDiv">
    <img src="bull.jpg" id="img2"  Style="CONTAINER:positioned;position:absolute;
    top:360px;left:560px;236px;height:118px;" onMouseMove=imgMove()>
   </div>
 </body>
</html>

posted on 2009-12-29 02:04  RIVERSPIRIT  阅读(274)  评论(0)    收藏  举报