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

229
Visualizações
When URL changes on scroll to a certain hash, add a class to a div

My URL hash changes on scroll from

  • www.website.com#section--1
  • www.website.com#section--2
  • www.website.com#section--3

and so on. It's a fullpage-scrolling effect.

What I want to do is to add the class .draw-shirt to the div #shirt when the URL changes on scroll to #section--2.

I tried this code:

$(document).ready(function () {

        if (window.location.href.indexOf("emotion--2") > -1) {
            $('#shirt').addClass('draw-shirt');
        }
    });
        
        

$(window).scroll(function () {
    
        function locationHashChanged() {
            if(window.location.href.indexOf("emotion--2") > -1) {
                $('#shirt').addClass('draw-shirt');
             }
        }

    });

It's working, if the URL is www.website.com#section--2 on load but not on scroll.

The code

function isScrolledIntoView(elem) {...etc... 

is not working here because of the fullpage-scrolling-effect.

Thanks for helping.

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

0

I think you could use the native hashchange event of the window object.

window.addEventListener('hashchange', function() {
    if (location.hash === '#emotion--2') {
        // your code to add class
   } 
});
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