简体   繁体   English

帮助修改JavaScript脚本

[英]Help modifying a JavaScript script

I have found a script that adds mouse trail on Opera's mouse gesture. 我发现了一个脚本,可在Opera的鼠标手势上添加鼠标轨迹。 Very nice done but with one problem. 做得很好,但有一个问题。 It detects when the mouse button is down and starts to draw a line BUT it doesn't detect when the mouse button is released. 它检测何时按下鼠标按钮,并开始绘制线条,但没有检测到释放鼠标按钮的时间。 The trail is displayed for an amount of time (1 second). 路径显示了一段时间(1秒)。 Can the script be updated so that the trail is present on screen as long as the button mouse is pressed ? 是否可以更新脚本,以便在按住按钮鼠标时在屏幕上显示轨迹?

The script was found in http://extendopera.org/userjs/content/gesture-tails 该脚本位于http://extendopera.org/userjs/content/gesture-tails

var GestureTrail={
//options:
  opacity:1,
  color:'#f27',


        canvas:null,
        _2d:null,
        start:null,
        cur:null,
        isdown:false,
        init:function(){

        /* create a transparent canvas element the size of
           the full window and insert it into the document */
          var canvas=document.createElement('canvas');
          canvas.height=window.innerHeight;
          canvas.width=window.innerWidth;
          document.body.appendChild(canvas);
          canvas.style="position:fixed;top:0;display:none;z-index:-999;left:0;opacity:"+this.opacity+";";
          this.canvas=canvas;

        /* grab the 2d methods for the canvas element */
          this._2d=this.canvas.getContext('2d');

    window.addEventListener("mousemove",function(e){GestureTrail.draw(e);},0);
    window.addEventListener("mouseup",function(e){GestureTrail.release();},0);
        },
        click:function(e){
          if(e.button!=2){return true;} // if not rightclick
          this.start={x:e.clientX,y:e.clientY}; // set the line start-point to the mouse position
                this._2d.strokeStyle=this.color;
          this.isdown=true;
          setTimeout(function(){GestureTrail.release();},1000); // thanks to Somh for thinking of this
          },
        draw:function(e){
          if(!this.isdown){return;} // if the mouse isn't down
          this.canvas.style.zIndex="999";    // bring the canvas element to the top 
          this.canvas.style.display="block"; /* (must be done on move - if done on mousedown
                                                it obscures text selection (HotClick) context menu) */
                this.cur={x:e.clientX,y:e.clientY}; // set point to begin drawing from
    this._2d.beginPath();
                this._2d.moveTo(this.start.x,this.start.y);
                this._2d.lineTo(this.cur.x,this.cur.y);
                this._2d.stroke();
    this.start=this.cur; /* sets the startpoint for the next mousemove to the
                             current point, otherwise the line constantly restarts
                             from the first point and you get a kind of fan-like pattern */
        },
        release:function(){
          this._2d.clearRect(0,0,window.innerWidth,window.innerHeight); // wipe the trails from the entire window
          this.isdown=false;
          this.canvas.style.zIndex="-999"; // send the canvas element back down below the page
          }
};

window.opera.addEventListener("BeforeEvent.mousedown",function(e){GestureTrail.click(e.event);},0);
window.addEventListener('DOMContentLoaded',function(){GestureTrail.init();},0);

remove: 去掉:

  setTimeout(function(){GestureTrail.release();},1000); // thanks to Somh for thinking of this

thats at the end of the click function. 多数民众赞成在点击功能的末尾。 that should be all 那应该是全部

but that is a site for real programming questions, not for customers to look for programms to do their work without payment 但这是一个真正的编程问题的网站,而不是让客户寻找无需付费即可完成工作的程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM