jquery implements the sidebar following the scroll bar (compatible IE6) _jquery

Source: Internet
Author: User

Part of the shopping site with this function to put shopping cart or commodity classification navigation, so that the product page is very long, the sidebar can always be fixed to play its due role, and some sites with this feature to the sidebar ads.

jquery Code:

Copy Code code as follows:

var Rollset = $ (' #Roll ')//Check object, #sidebar-tab is the ID to be fixed with the scroll bar, can be changed as needed
var offset = Rollset.offset ();
$ (window). Scroll (function () {
Check whether the top of the object is visible in the viewer
var scrolltop = $ (window). scrolltop ();
if (Offset.top < scrolltop) {
Rollset.addclass (' fixed ');
}else{
Rollset.removeclass (' fixed ');
}
});

CSS code:
Copy Code code as follows:

. fixed{position:fixed; top:20px;}
. Fixed{_position:absolute _top:expression (20+ (novalue = Document.documentElement.scrollTop? DOCUMENT.DOCUMENTELEMENT.SCROLLTOP:DOCUMENT.BODY.SCROLLTOP)) + ' px '); Compatible 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.