简体   繁体   中英

<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. On its own HTML file, all of the links and hover events are working. 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. This javascript file controls the elements of a snake game, and includes a requestAnimationFrame game-loop that runs recursively.

How can I stop this JS file from blocking these other events?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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