简体   繁体   中英

How To Change Div To “Fixed” After Scroll

At academicearth's about page, they have an <aside> tag on the right that is fixed once you start to scroll.

http://academicearth.org/about/

How is this done?

On top of the <aside> tag becoming fixed , it's also moved over just a bit to the right to fit the contents that appear from scrolling.

use scroll event..

$(document).scroll(function(e)
{ 
    //grab position of scrollbar
    position=$(document).scrollTop();
    //when position match a height
    if(position==desired_height)
    {
      //grab element 
      $('ele').css('position','fixed');
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM