Skip to content

Instantly share code, notes, and snippets.

@yaroslavKas
Created October 4, 2016 10:36
Show Gist options
  • Save yaroslavKas/f6daddaea420d6194d63aeec4bde61c1 to your computer and use it in GitHub Desktop.
Save yaroslavKas/f6daddaea420d6194d63aeec4bde61c1 to your computer and use it in GitHub Desktop.
Фиксированный блок при скролле
document.addEventListener("DOMContentLoaded", function() {
function scrollWidget(){
var widget = document.getElementById('villa-calendar-wrapper'),
headerHeight = document.getElementById('header-outer').offsetHeight,
widgetPositionParams = widget.getBoundingClientRect(),
scrollHeight = window.pageYOffset || document.documentElement.scrollTop;
if(widgetPositionParams.top < scrollHeight){
widget.style.top = headerHeight + 20 + 'px';
widget.classList.add('fixed');
}
else{
widget.classList.remove('fixed');
}
}
scrollWidget();
window.onscroll = function(){
scrollWidget();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment