Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$(window).scroll(function() {
var sb_m = 20; // отступ сверху и снизу
var mb = 500; // высота подвала с запасом
var st = $(window).scrollTop();
var sb = $(".sticky-block");
var sbi = $(".sticky-block .inner");
var sb_ot = sb.offset().top;
var sbi_ot = sbi.offset().top;
var sb_h = sb.height();
if (sb_h + $(document).scrollTop() + sb_m + mb < $(document).height()) {
if (st > sb_ot) {
var h = Math.round(st - sb_ot) + sb_m;
sb.css({ "paddingTop": h });
} else {
sb.css({ "paddingTop": 0 });
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment