How to make a fixed positional div to some point?

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

+4
source share
1 answer

You can do this with jQuery quite 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';
   }

};
+4
source

Source: https://habr.com/ru/post/1527043/


All Articles