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

82
Visualizações
My location.href is overriding another function of mine

I have a location.href code added to identify the section of the page the user is viewing in the URL (www.example.com/#section1, www.example.com/#section2 etc.)

  document.getElementById('link_no' + (i + 1)).classList.add('active-link');
        let currentLocation = location.href;
        currLocationArray = currentLocation.split("#");
        currentLocation = currLocationArray[0];
        currentLocation += `#section${i+1}`;
        
        location.href = currentLocation;
// scroll section
let sectionOfI = document.getElementById(`section${i+1}`);
        let scrollArea = getOffset(sectionOfI);
          scrollEventNew(scrollArea.top,e);

but it's messing up the smooth scroll of my JS built scroll function



function scrollEventNew(y , event) {
      window.scrollTo({
        left: 0,
        top: y,
        behavior: 'smooth'
    })  
    }

is there a way to keep both codes without commenting out my location.href?
I can't opt for a CSS smooth scroll either.

about 4 years ago · Juan Pablo Isaza
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