SoFunction
Updated on 2025-02-28

Summary of prototype declaration and usage of js drag

Below is a prototype statement about js drag and drop I wrote: the code is as follows

Issues to note include:

Who is the pointing pointing to-find the object you are pointing to

Use of () method

3. What is the difference between directly assigning the parent prototype to the child and using for to assign it to the child?

for example:

for(var i in )
{
  [i]=[i];----------Children change,Its parent will not be affected
}

 =;---------Assign prototypes directly to sub-levels,会导致当Children change时,The parent will change as well。

The code is as follows

<html>
<head>
<style>
#div1 {width:100px; height:100px; background:red; position:absolute;}
#div2 {width:100px; height:100px; background:yellow; position:absolute;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Drag and drag--Object-oriented</title>
<script>
=function()
{
  new Drag('div1');
  new LimitDrag('div2');
}
function Drag(id)
{
   var _this=this;//This this means p1   =0;
   =0;
   =(id);
   =function(ev){//When pressed, there is an event, which is passed to the following event    _this.fnDown(ev);
    return false;
   }
}; 
=function(ev)
{
    var _this=this;
    var oEvent=ev||event;
    =;
    =;
    =function(ev){//There is an event when moving       _this.fnMove(ev);
    }
    =function(){
       _this.fnUp();
    }
}; 
 =function(ev)
{
      var oEvent=ev||event;
      =+'px';
      =+'px';
};
=function()
{
     =null;
     =null;
};
//Inherit all attributes of Dragfunction LimitDrag(id)
{
    (this,id);//This refers to the object of LimitDrag new}
//Get Drag method and traverse its prototypefor(var i in )
{
  [i]=[i];
}
//The method of changing the fnMove of Drag=function(ev)
{
  var oEvent=ev||event;
  var l=;
  var t=;
  if(l>)
  {
    l=;
  }
  else if(l<0)
  {
    l=0;
  }
   if(t>)
  {
    t=;
  }
  else if(t<0)
  {
    t=0;
  }
   =l+'px';
   =t+'px';
}
</script>
</head>
<body>
<div >
</div>
<div >
</div>
</body>
</html>

The above is all about this article, I hope it will be helpful to everyone's learning.