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