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.
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!
position:fixed
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"; }
, https://www.virendrachandak.com/techtalk/make-a-div-stick-to-top-when-scrolled-to/
, , ?
CSS: fixed; , .
CSS
http://csswizardry.com/2012/02/pragmatic-practical-font-sizing-in-css/
uses jQuery with a scroll lock plugin: https://gist.github.com/837729