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

86
Visualizações
Is there a JavScript event when DOM content stops updating?

I am building a website whose main component is a slideshow that is in the background of the whole site. Its image and description are on a timer so they change every couple of seconds.

The problem is that when the user leaves the site for a long enough time, the timer is still running, but the content is not present anymore, so when they navigate back to the page, it tries to catch up to the timer and it goes through the slideshow very quickly until it gets to the right state.

My current (very simple) solution for this is that I am cheching if the document is in focus before going to the next slide:

    //- show next slide
    function nextSlide() {
        if (!document.hasFocus()) return
    ...

The problem with this solution is that if there are multiple windows on the screen and the page is not in focus, then the slideshow won't play, which isn't the intended bahaviour.

My question is: is there any JavaScript event that I can rely on to be called when the document is unloaded but the scripts are still running (if that even is what is happening here), so I can stop the timer and start it again when the user navigates to the site?

Edit: when I said "leaving the site", I meant leaving the tab or switching to another window so the site loses focus.

Link to the site: https://dev.jazzpuntbigband.com

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So, I fixed my own issue. Turns out all I had to do was follow this guide from MDN Web Docs.

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