Created
December 1, 2016 08:22
-
-
Save Nikeshsuwal/9d1b4c2807fdf6c7546d0144adbadb49 to your computer and use it in GitHub Desktop.
fixed widget on scroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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