简体   繁体   English

<a>链接和:当我包含某个 JavaScript 文件时,hover 事件不起作用</a>

[英]<a> links and :hover events not working when I include a certain JavaScript file

I'm working on a navbar for my website.我正在为我的网站制作导航栏。 To develop it, I started a new HTML file so I could play around with the code without changing my main index.html file.为了开发它,我创建了一个新的 HTML 文件,这样我就可以在不更改主 index.html 文件的情况下使用代码。 On its own HTML file, all of the links and hover events are working.在其自己的 HTML 文件中,所有链接和 hover 事件都在工作。 However, when I brought the header code into my working index.html file, the links do not work, and the:hover css events no longer work. However, when I brought the header code into my working index.html file, the links do not work, and the:hover css events no longer work. I narrowed down the problem to the inclusion of a Javascript file.我将问题缩小到包含 Javascript 文件。 This javascript file controls the elements of a snake game, and includes a requestAnimationFrame game-loop that runs recursively.这个 javascript 文件控制蛇游戏的元素,并包含一个递归运行的 requestAnimationFrame 游戏循环。

How can I stop this JS file from blocking these other events?如何阻止此 JS 文件阻止这些其他事件?

Here is the game-loop...这是游戏循环...

function main(currentTime) {

    if (gameOver) {
        if (confirm("You lost. Press ok to restart.")) {
            window.location ="/"
        }
        return
    }

    window.requestAnimationFrame(main)
    const secondsSinceLastRender = (currentTime - lastRenderTime) / 1000;
    if (secondsSinceLastRender < 1 / SNAKE_SPEED) return
    
    // console.log("Render")
    lastRenderTime = currentTime
    
    update()
    draw()
}

window.requestAnimationFrame(main)

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

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