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
Sticky div scrolls too far

I have a jquery code which makes an existing element follow the scroll of the user. I want it to stop when reaching a certain element #header-line, but it's not consistent. On some PDPs it scrolls and stops there, on others, it scrolls past the line.

Page: https://www.norli.no/to-pappaer (Code is not activated here)

jQuery


require(['jquery'], function($){
  $(document).ready(function() {

(function($) {
    var element = $('.product-add-form'),
        originalY = element.offset().top;

    var hr = $('#header-line > hr');
        topOfLine = hr.offset().top;

    var topMargin = 250;

    element.css('position', 'relative');

    $(window).on('scroll', function(event) {
        var scrollTop = $(window).scrollTop();
        var nextPosition = scrollTop - originalY + topMargin;
        var maxPositionAllowed = topOfLine - 1000;

        element.stop(false, false).animate({
          top: scrollTop + 250 < originalY ? 0 : Math.min(nextPosition, maxPositionAllowed )
        }, 0);
    });
})(jQuery);
  });
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could definitely take advantage of using position: sticky if you are able to make sure all parent elements of the sticky element have overflow: visible

In that link you posted, if you wanted .product-add-form to be position: sticky you would have to make sure .off-canvas-wrapper has the overflow: hidden changed to overflow: visible.

I made an example fiddle of that page you shared so you could see how easy it would be to make that side form sticky.

https://jsfiddle.net/treckstar/d30phae8/8/

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