Skip to content

Instantly share code, notes, and snippets.

@Nikeshsuwal
Created December 1, 2016 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nikeshsuwal/9d1b4c2807fdf6c7546d0144adbadb49 to your computer and use it in GitHub Desktop.
Save Nikeshsuwal/9d1b4c2807fdf6c7546d0144adbadb49 to your computer and use it in GitHub Desktop.
fixed widget on scroll
$(function() {
if ($('#subs-wrapper').length) {
sub_width = $('#subs-wrapper').parent('div').width()
var el = $('#subs-wrapper');
var stickyTop = $('#subs-wrapper').offset().top - 100;
var stickyHeight = $('#subs-wrapper').height();
screen_width = $(window).width();
if ( 767 < screen_width){
$(window).scroll(function() {
var limit = $('#footer-top').offset().top - stickyHeight - 100;
var windowTop = $(window).scrollTop();
if (stickyTop < windowTop) {
el.css({
position: 'fixed',
top: 35,
width: sub_width
});
} else {
el.css('position', 'static');
}
if (limit < windowTop) {
var diff = limit - windowTop+35;
el.css({
top: diff
});
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment