thingspeak/app/assets/javascripts/sidebar.js

36 lines
935 B
JavaScript
Raw Normal View History

2014-02-28 19:57:58 +01:00
// execute on window load (and not document.ready), so that the sidebar is positioned correctly
2014-07-23 19:45:15 +02:00
$(window).on('page:load load', function() {
// if affix function exists
if ($.fn.affix) {
2014-02-28 19:57:58 +01:00
// add sidebar affix, wrapped in a timeout so that it displays correctly
setTimeout(function() {
$('#bootstrap-sidebar').affix();
}, 100);
// add sidebar scrollspy
$(document.body).scrollspy({ target: '#leftcol', offset: 300 });
// add smooth scrolling
$("#bootstrap-sidebar li a[href^='#']").on('click', function(e) {
// prevent default anchor click behavior
e.preventDefault();
// store hash
var hash = this.hash;
// animate
$('html, body').animate({
scrollTop: $(this.hash).offset().top - 90
}, 300, function(){
// when done, add hash to url
// (default click behaviour)
window.location.hash = hash;
});
});
}
});