Firefox鼠标事件无效

时间:2014-02-23 06:26:48

标签: javascript html firefox canvas

你好,所以我正在制作一个带有画布和java脚本的游戏,我刚刚下载并安装在我的计算机上以便在Firefox上测试它,但鼠标事件不起作用。 Chrome和IE适用于我正在使用的系统,但Firefox不支持。

任何帮助将不胜感激。这是我的代码。

game.c.addEventListener( "mousedown", game.mouseClick, false )
 game.mouseClick = function(  ) {
     game.mouseX = event.x;
     game.mouseY = event.y;

     game.mouseX -= game.c.offsetLeft;
     game.mouseY -= game.c.offsetTop;
 }

1 个答案:

答案 0 :(得分:3)

对于Firefox,事件将传递给函数,因此您的代码应如下所示:

game.c.addEventListener( "mousedown", game.mouseClick, false )
 game.mouseClick = function(event) {

 game.mouseX = event.x;
 game.mouseY = event.y;

 game.mouseX -= game.c.offsetLeft;
 game.mouseY -= game.c.offsetTop;
 }