gpt4 book ai didi

Javascript "onmousemove()"在 Chrome 中有效,但在 Firefox 中无效

转载 作者:行者123 更新时间:2023-12-03 12:21:11 26 4
gpt4 key购买 nike

我已经尝试过谷歌搜索,但找不到任何解决方案。

当鼠标悬停在底部的四个塔上时,它们应该显示不同的图像(不太透明)。这在 Google Chrome 中完美运行,但在 Firefox 中则不行。

这是网站:http://cdelphinus.com/test/mormontowerdefense.html (您可以右键单击->查看源代码)查看整个代码(app.js)

这是问题代码:

在我的 HTML 中:

<canvas id="Canvas_One" width="1160" height="580" style="border:2px solid yellow;          background-color:black; padding-left:0;margin-left:0;" onmousemove="lolol(event)"    onclick="haha(event)"></canvas>

在我的 app.js 文件中:

这是我的问题的一个非常浓缩的版本,这在 Chrome 中有效,但在 Firefox 中无效:

//function lolol(event) {
// event = event || window.event;
// alert(event.x);
//}

我有一种感觉,一旦上面的警报出现在 Firefox 中,其余的就会神奇地修复。

这是正在发生的事情的更详细版本

function lolol(event) {
event = event || window.event;
ix = event.x - canvas.offsetLeft + 10;
iy = event.y- canvas.offsetTop + document.body.scrollTop;
//...
if(iy > 510) {
var dist = Math.round(ix / 50) - 1;
if(dist < towerpurchaseoptions.length){
towerpurchaseoptions[dist].isActive = true;
//textout(towerpurchaseoptions[dist].name);
for(var i=0; i<towerpurchaseoptions.length; i++) {
if(i != dist) {
towerpurchaseoptions[i].isActive = false;
}
}
}
}
//....
}

如果 towerpurchaseoptions[n].isActive == true,则图像将替换为透明度较低的图像

最佳答案

我检查了你的问题,这只是因为

function lolol(event) {
event = event || window.event; //For IE

ix = event.x - canvas.offsetLeft + 10;

//这里 ix 正在转 nan

    iy = event.y- canvas.offsetTop  + document.body.scrollTop;

//这里 iy 正在旋转 nan

那为什么呢?因为事件在 Firefox 中没有属性 .x 可能会出现一些问题,您可以将其更改为

 function lolol(event) {
event = event || window.event; //For IE

ix = event.clientX - canvas.offsetLeft + 10;


iy = event.clientY- canvas.offsetTop + document.body.scrollTop;

它会起作用,谢谢。

关于Javascript "onmousemove()"在 Chrome 中有效,但在 Firefox 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24444147/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com