Skip to content

Instantly share code, notes, and snippets.

@m-bo-one
Created December 15, 2015 21:14
Show Gist options
  • Save m-bo-one/94a63e16bb10043f8276 to your computer and use it in GitHub Desktop.
Save m-bo-one/94a63e16bb10043f8276 to your computer and use it in GitHub Desktop.
// our function that decides weather the navigation bar should have "fixed" css position or not.
var stickyBlock = function () {
if (is_wide()) {
// grab the initial top offset of the navigation
var stickyBlockOffsetTop = $('#main_div').offset().top;
var scrollTop = $(window).scrollTop(); // our current vertical position from the top
// if we've scrolled more than the navigation, change its position to fixed to stick to top, otherwise change it back to relative
if (scrollTop > stickyBlockOffsetTop) {
$('.sticky').css({'position': 'fixed', 'top': '0'});
} else {
$('.sticky').css({'position': 'absolute', 'top': '0'});
}
} else {
$('.sticky').css({'position': '', 'top': ''});
}
};
// run our function on load
stickyBlock();
// and run it again every time you scroll
$(window).scroll(function () {
stickyBlock();
});
//init dom events n stuff
$(document).ready(function () {
$('.tab-survey').addClass('active')
var ap = new AnswerProcessor();
ap.init(CONFIG.categoriesDict);
if (localStorage.getItem('show_overlay_on_polifit')) {
popup.trigger('click');
localStorage.removeItem('show_overlay_on_polifit');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment