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

123
Visualizações
Asp.net Core JQuery scroll to div on page load not working

I have run up against a little problem. I am trying to get the page to scroll to a specific point on page load but I'm not getting anywhere. The code I have used is below. For some reason it doesn't seem to be running at all.

<script type="text/javascript">
        // scroll past header on page load
        function scrollToDiv() {
            $(document).ready(function () {
                var ele = $('html, body').animate({ scrollTop: $('#tree').position().top }, 500, 'linear');
            });
        };


        scrollToDiv();

    </script>

If you have any suggestions as to why it is not working I would certainly appreciate it.

I am building using ASP.NET Core. The above jQuery code worked on an old webforms project so I have no idea why it isn't working now.

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

0

To do this with jQuery:

<script>
$(function(){
    const top = $('#tree').position().top;
    $('html, body').animate({ scrollTop: top }, 500, 'linear');
});
</script>

However, you don't need jQuery for this:

<script>
window.addEventListener('DOMContentLoaded', () => {
    const target = document.getElementById('tree');
    target.scrollIntoView({ behavior: 'smooth', block: 'start' });
});
</script>

Window: DOMContentLoaded event - Web APIs | MDN
Element.scrollIntoView() - Web APIs | MDN

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