Question

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.

Was it helpful?

Solution

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';
   }

};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top