Home > Web Front-end > JS Tutorial > Jquery implements fixed sidebar following scroll bar (compatible with IE6)_jquery

Jquery implements fixed sidebar following scroll bar (compatible with IE6)_jquery

WBOY
Release: 2016-05-16 16:53:46
Original
1352 people have browsed it

Some shopping websites use this function to place shopping cart or product category navigation, so that when the product page is very long, the sidebar can always play its due role. Some websites use this function to place ads in the sidebar.

jQuery code:

Copy 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:
Copy code The code is 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 with IE6
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template