Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 鼠标悬停在kineticjs矩形事件上_Javascript_Html_Html5 Canvas_Kineticjs - Fatal编程技术网

Javascript 鼠标悬停在kineticjs矩形事件上

Javascript 鼠标悬停在kineticjs矩形事件上,javascript,html,html5-canvas,kineticjs,Javascript,Html,Html5 Canvas,Kineticjs,正如你在我的书中看到的。或者在我下面的代码中,我试图让事件发生。将鼠标悬停在框上并单击空格键时,确认窗口将弹出。单击“是”后,该框将被删除 错误/问题在于,一旦删除该框并再次单击空格键,就会出现相同的提示。我想我已经通过使用rTwo.setlisting(false)关闭监听功能解决了这个问题; layer.drawHit() 无论如何,任何帮助都将不胜感激谢谢。 代码: 这就是你的逻辑:在鼠标上注册onkeypress函数,该函数检查按键是否按下,如果该键是空格键,则显示提示 鼠标悬停->寄

正如你在我的书中看到的。或者在我下面的代码中,我试图让事件发生。将鼠标悬停在框上并单击空格键时,确认窗口将弹出。单击“是”后,该框将被删除

错误/问题在于,一旦删除该框并再次单击空格键,就会出现相同的提示。我想我已经通过使用
rTwo.setlisting(false)关闭监听功能解决了这个问题;
layer.drawHit()

无论如何,任何帮助都将不胜感激谢谢。

代码:

这就是你的逻辑:在鼠标上注册onkeypress函数,该函数检查按键是否按下,如果该键是空格键,则显示提示

鼠标悬停->寄存器功能

功能->检查按键->是否为空格键?->显示提示

如果您看到这一点,您将检查空格键是否为mouseover,因为mouseover只是注册一个函数。基本上,您需要重新检查鼠标是否位于矩形中

 rTwo.on('mouseover mousemove', function(){
      document.onkeypress = function(e) { 
           e = e || window.event;
           var charCode = (typeof e.which == "number") ? e.which : e.keyCode;
           if (charCode == 32 && rTwo.intersects(stage.getUserPosition())) {
                var b1 = confirm("Would you like to delete router 2?");
                if (b1 == true){
                     rTwo.hide();
                     layer.drawHit();  // or whichever layer rTwo is in
                     layer.draw();
                     rTwo.setListening(false);
                }
                else if (b1 == false){
                     layer.draw();  // you don't really need to redraw this here as nothing is changed
                }
           }
      };
 });

噢,
和&rTwo.相交(stage.getUserPosition())
明白了。再次感谢您的帮助,Octo先生。另外,正如您所知,.intersects()函数有点慢,所以如果您在RTWO中,您可能需要一些其他的测试方法。这把小提琴真的适合你们吗?我试过了,它只是在没有确认的情况下删除了rect。
 rTwo.on('mouseover mousemove', function(){
      document.onkeypress = function(e) { 
           e = e || window.event;
           var charCode = (typeof e.which == "number") ? e.which : e.keyCode;
           if (charCode == 32 && rTwo.intersects(stage.getUserPosition())) {
                var b1 = confirm("Would you like to delete router 2?");
                if (b1 == true){
                     rTwo.hide();
                     layer.drawHit();  // or whichever layer rTwo is in
                     layer.draw();
                     rTwo.setListening(false);
                }
                else if (b1 == false){
                     layer.draw();  // you don't really need to redraw this here as nothing is changed
                }
           }
      };
 });