Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

213
Visualizações
<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)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I figured out the problem. A separate JS file I have generates a grid that is around 99vh height and 99vw width. The grid is used for the snake element. Because of the Z-index, the on-hover events were being blocked by this giant invisible element. I set the header z-index to 900, just in case ;), and now every thing is working nicely

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda