Last active
December 26, 2022 13:20
-
-
Save karamansky/95ece004b3c7ce7478492c854e25977e to your computer and use it in GitHub Desktop.
JS: Зафиксировать блок при прокрутке
This file contains hidden or 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
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