Pergunta

I have a div with applied property position: fixed;. I need to stop this property on some height of screen scroll. Any ideas? I just need the css code only.

Foi útil?

Solução

You can do it with jQuery pretty easily:

$(window).scroll(function(){
   if ($(window).scrollTop() >= target) {  // change target to number
      $("#el").css('position', 'relative');
   }
});

or pure JavaScript:

window.onscroll = function(){

   if(window.scrollY >= target) { // change target to number
      document.getElementById('el').style.position = 'relative';
   }

};
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top