Creating a Scrollable Div

How to make a div fixed to detect scrolling by users. Example: Facebook's right sidebar, it gets stuck when a certain scroll position is reached.

+5
source share
5 answers

position:fixed- the answer.
But you can always look at the source of the website if you want to know how they do something. Very educated!

+7
source

Track if we scroll.

if($(window).scrollTop() > 0){
  //we're scrolling our position is greater than 0 from the top of the page.
  $("#element").css({'position' : 'fixed'});
}

* CHANGE

Do it without jQuery ..

if(window.scrollTop() > 0){
  document.getElementById('element').style.position="fixed";
}
+5
source

, , ?

CSS: fixed; , .

CSS

+1

All Articles