You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
/* ------------------------------------------------------------------------------ |
|
* |
|
* # Sticky sidebar with native scrollbar |
|
* |
|
* Specific JS code additions for layout_sidebar_sticky_native.html blank page |
|
* |
|
* Version: 1.0 |
|
* Latest update: Aug 1, 2015 |
|
* |
|
* ---------------------------------------------------------------------------- */ |
|
|
|
$(function() { |
|
|
|
|
|
// Resize sidebar on scroll |
|
// ------------------------------ |
|
|
|
// Resize detached sidebar vertically when bottom reached |
|
function resizeDetached() { |
|
$(window).on('load scroll', function() { |
|
if ($(window).scrollTop() > $(document).height() - $(window).height() - 40) { |
|
$('.sidebar-detached').addClass('fixed-sidebar-space'); |
|
} |
|
else { |
|
$('.sidebar-detached').removeClass('fixed-sidebar-space'); |
|
} |
|
}); |
|
} |
|
|
|
|
|
// Affix detached sidebar |
|
// ------------------------------ |
|
|
|
// Init nicescroll when sidebar affixed |
|
$('.sidebar-detached').on('affix.bs.affix', function() { |
|
resizeDetached(); |
|
}); |
|
|
|
// Attach BS affix component to the sidebar |
|
$('.sidebar-detached').affix({ |
|
offset: { |
|
top: $('.sidebar-detached').offset().top - 20 // top offset - computed line height |
|
} |
|
}); |
|
|
|
|
|
// Remove affix and scrollbar on mobile |
|
$(window).on('resize', function() { |
|
setTimeout(function() { |
|
if($(window).width() <= 768) { |
|
|
|
// Remove affix on mobile |
|
$(window).off('.affix') |
|
$('.sidebar-detached').removeData('affix').removeClass('affix affix-top affix-bottom'); |
|
} |
|
}, 100); |
|
}).resize(); |
|
|
|
});
|
|
|