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

238
Visualizações
Is there a way to know if the user is on a particular heading, paragraph or a div etc

I was trying to find a way to start an animation only if the user is on it, at first I tried getting screen size, and its works, but its not an optimal solution. Once I was googling I found something where we could get ID (by the ID tag) while scrolling, if somehow I could get the ID while scrolling down, I could use a simple JavaScript function to play the animation. is there any way?

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

0

Okay I found that by my own. What I was trying to do? I wanted to start an animation (skills bar) only when the user is seeing it/on it/have passed previous information. I did this by using section, JavaScript and then trigger the animation when user is on it.

AN EXAMPLE (Im sorry for messy code, I dont know to align code here)

 <section id="name">
        <div class="hello">
<h1>Hello world</h1>
</div>
    </section>
    
        <section id="aboutMe">
        <div class="hello">
<h1>Hello world</h1>
</div>
    </section>
    
        <section id="skills">
        <div class="hello">
             <h1>these are my skills</h1>
</div>
    </section>

JAVASCRIPT:

     var element = document.querySelector("#skills");
    
    function isInViewPort(element) {
    // Get the bounding client rectangle position in the viewport
    var bounding = element.getBoundingClientRect();

    // Checking part. Here the code checks if it's *fully* visible
    // Edit this part if you just want a partial visibility
    if (
        bounding.top >= 0 &&
        bounding.left >= 0 &&
        bounding.right <= (window.innerWidth || document.documentElement.clientWidth) &&
        bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight)
    ) {
        return true;
    } else {
        return false;
    }
}

    var element = document.querySelector("#skills");
    
    if (isInViewPort(element)) {
        alert('true')
    }

hope this will help someone in the future

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