Jquery implements fixed orientation of the sidebar following the scroll bar (compatible with IE6) _ jquery

Source: Internet
Author: User
The Sidebar scroll up and down with the scroll bar and is always fixed in one location. Many websites and bloggers now have this function. Some shopping websites use this function for shopping cart or product category navigation, when the product page is very long, the sidebar can always play its due role. Some websites use this function to advertise the sidebar.

JQuery code:

The Code is as follows:


Var rollSet = $ ('# roll'); // check the object, # sidebar-tab is the ID to be fixed with the scroll bar, which can be changed as needed
Var offset = rollSet. offset ();
$ (Window). scroll (function (){
// Check whether the top of the object is within the visible range of the browser
Var scrollTop = $ (window). scrollTop ();
If (offset. top <scrollTop ){
RollSet. addClass ('fixed ');
} Else {
RollSet. removeClass ('fixed ');
}
});


CSS code:

The Code is as follows:


. Fixed {position: fixed; top: 20px ;}
. Fixed {_ position: absolute; _ top: expression (20 + (noValue = document.doc umentElement. scrollTop? Document.doc umentElement. scrollTop: document. body. scrollTop) + 'px ');} // compatible with IE6

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.