Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save karamansky/95ece004b3c7ce7478492c854e25977e to your computer and use it in GitHub Desktop.
Save karamansky/95ece004b3c7ce7478492c854e25977e to your computer and use it in GitHub Desktop.
JS: Зафиксировать блок при прокрутке
if($('.checkout-right').length){
var offset_this = $('.checkout-right').offset().top;
var scr_top = $(document).scrollTop();
var parent_box_height = $('.chechout-box').outerHeight(true);
$(document).scroll(function() {
scr_top = $(document).scrollTop();
if((scr_top > offset_this)){
$('.checkout-right').addClass('fixed');
$('.checkout-right').css('right', $('.chechout-box').offset().left);
if(scr_top >= parent_box_height){
$('.checkout-right').removeClass('fixed');
$('.checkout-right').addClass('absolute');
}else{
$('.checkout-right').removeClass('absolute');
}
}else{
$('.checkout-right').removeClass('fixed');
$('.checkout-right').removeClass('absolute');
}
});
}
// &.fixed
// position: fixed
// top: 0
// right: 0
// z-index: 10
// &.absolute
// position: absolute
// bottom: 35px!important
// right: 0!important
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment