当draggable属性设置为false时,不会删除事件

时间:2017-04-26 13:33:56

标签: javascript svg

var attachEvents =(function(){           var events ="点击mouseover mouseout mousedown mouseup mousemove keydown keyup dragstart dragend drag" .split("");           for(var i = 0; i             })(事件[I]);            }       })();         Object.prototype.draggable =函数(f){           this.setAttribute("可拖动"中,f);           var currentX,currentY,clickX,clickY;

         function mouseMove(e){
         e.preventDefault(); 
         if(this.getAttribute("click")=="true"){
            currentX+=e.clientX-clickX;
            currentY+=e.clientY-clickY;
            clickX+=e.clientX-clickX;
            clickY+=e.clientY-clickY;
            if(this.hasAttribute("cx")){
             this.setAttribute("cx",currentX);
             this.setAttribute("cy",currentY);   
            }
            else{
             this.setAttribute("x",currentX);
             this.setAttribute("y",currentY);
            }

             }
         };
        function mouseDown(e){
            e.preventDefault();
            this.setAttribute("click","true");
            click=true;
            clickX=e.clientX;
            clickY=e.clientY;
         };
       function mouseUp(){
            this.setAttribute("click","false");
        };
        if(this.getAttribute("draggable")=="true"){
         if(this.hasAttribute("cx")){
             currentX=Number(this.getAttribute("cx"));
             currentY=Number(this.getAttribute("cy"));
             this.mousedown(mouseDown);
             this.mouseup(mouseUp);
             this.mousemove(mouseMove);  
         }      
         else{
             currentX=Number(this.getAttribute("x"));
             currentY=Number(this.getAttribute("y"));
             this.mousedown(mouseDown);
             this.mouseup(mouseUp);
             this.mousemove(mouseMove); 
         }
      }
      else if(this.getAttribute("draggable")=="false"){
          this.unmousedown(mouseDown);
          this.unmouseup(mouseUp);
          this.unmousemove(mouseMove);
      }
  };

0 个答案:

没有答案