json方式的面向对象、拖拽

//json方式的面向对象
var obj= {
    a:12,
    b:5,
    c:function(){
        alert(this.a)//12
    }
}
obj.c();//12
//命名空间
var miaov={};
miaov.common={
     myDel:function(){

      } ,
     myAdd:function(){
     
     }
};
miaov.fix={
   get:function(){
   
   },
    set:function(){
   
    }
};
miaov.common.myDel()
  • 拖拽
<script>
        window.onload=function(){
            new Drag('div1')
        };
        function Drag(id){
            var _this=this;
            this.disX=0;
            this.disY=0;
            this.oDiv = document.getElementById(id);
            thisoDiv.onmousedown=function(){
                _this.fnDown();
            };
         };
         Drag.prototype.fnDown=function(ev){
            var oEvent = ev || event;
            this.disX = oEvent.clientX - this.oDiv.offsetLeft;
            this.disY = oEvent.clientY - this.oDiv.offsetTop;
            document.onmousemove = function(){
                _this.fnMove();
            };
            document.onmouseup=function(){
                _this.fnUp();
            };
        }
        Drag.prototype.fnMove = function(ev){
            var oEvent = ev || event;
            this.oDiv.style.left = oEvent.clientX - this.disX+'px';
            this.oDiv.style.top = oEvent.clientY - this.disY+'px';
        };
        Drag.prototype.fnUp = function(){
            document.onmousemove=null;
            document.onmouseup=null;
        }
    </script>

猜你喜欢

转载自www.cnblogs.com/zhangxiaoqiong/p/10742820.html