[转]拖动

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
 .dom-one{ position:absolute;width:200px; height:100px; background:#D8F5F2;filter:alpha(opacity=100); border:2px solid #0CC;}
</style>


</head>

<body>
<div id="dom" class="dom-one">
 <div id="dom2" style="height:30px; background:#CCC; cursor:move">拖动灰色的DIV移动</div>
</div>
<br/><br/><br/><br/><br/><br/><br><br><br><br><br><br>

<div style="width:300px; height:200px; border:1px solid #CCC;"></div>

<script type="text/javascript">
 function move(matter,id){
   //受影响对象//移动对象
   var $=function(o){return document.getElementById(o);}
   
 
   var alpha=function(ob,val){if (document.all){
   ob.filters.alpha.opacity=val;
   }else{
   ob.style.opacity=val/100;}}
   var loadd=function(){
     var o=$(matter);
     var c=$(id);
     o.onmousedown=function(ev){
      var mxy=mouseMove(ev);
      var by={x:mxy.x-(c.offsetLeft),y:mxy.y-(c.offsetTop)};
      alpha(c,50);
      o.style.cursor="move";
      document.onmousemove=function(ev){
       var mxy=mouseMove(ev);
       c.style.left=mxy.x-by.x+"px";
       c.style.top=mxy.y-by.y+"px";
      };
      document.onmouseup=function(){
        alpha(c,100);
        window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
        this.onmousemove=null;
       }
     }
    }
    loadd();
  
  function mouseMove(e){
   e = e || window.event;
   var m=(e.pageX || e.pageY)?{ x:e.pageX, y:e.pageY } : { x:e.clientX + document.body.scrollLeft - document.body.clientLeft, y:e.clientY + document.body.scrollTop  - document.body.clientTop };
     return m;
  }
}
 move("dom2","dom")
 
 
 window.onload=function(){
 
     var  m={x:"wangkun",y:"rhythmk"};
     var v=m.x;
     alert(v);
    
 }
</script>
</body>
</html>

posted @ 2010-05-04 21:15  Rhythmk  阅读(237)  评论(1编辑  收藏  举报
Rhythmk 个人笔记