Sidebar not fixing properly with jquery ".css" function. #solved
Hi, in search for a fixed sidebar jQuery code, I found
this tutorial , which has
this fiddle example . The
html ,
css and
js codes are very simple, and while kept simple it works fine. Though, when I tried to insert it in
my sandbox project , something goes wrong. Within my project selectors specifications, the
js script goes like this:
- jQuery(document).ready(function () {
- var length = jQuery('.product-shop').height() - jQuery('#sidebar').height() + jQuery('.product-shop').offset().top;
- jQuery(window).scroll(function () {
- var scroll = jQuery(this).scrollTop();
- var height = jQuery('#sidebar').height() + 'px';
- if (scroll < jQuery('.product-shop').offset().top) {
- jQuery('#sidebar').css({
- 'position': 'absolute',
- 'top': '0'
- });
- } else if (scroll < length) {
- jQuery('#sidebar').css({
- 'position': 'absolute',
- 'bottom': '0',
- 'top': 'auto'
- });
- } else {
- jQuery('#sidebar').css({
- 'position': 'fixed',
- 'top': '0',
- 'height': height
- });
- }
- });
- });
But, as you can see in my sandbox, when the page is rendered and when the user scrolls down, the "else" statement seems to be ignored, not fixing the sidebar. The project is running on magento and bootstrap.
Any clue on where is the problem?