Check out this jQuery code I wrote to remove the sticky class while scrolling down:
$(window).scroll(function (e) {
if ($('.main_form_wrapper').length != 0) {
var window_scroll = $(window).scrollTop();
console.log(window_scroll, "current window scroll position")
var bottom_position = window_scroll + $('.main_form_wrapper').outerHeight(true);
console.log(bottom_position, "position of main form wrapper at the bottom")
var form_top_offset = $('.main_form_wrapper').offset().top;
console.log(form_top_offset, "offset of main form wrapper from the top")
var footer_top_offset = $('.top_footer').offset().top;
console.log(footer_top_offset,"offset of the top footer")
if (window_scroll > form_top_offset && bottom_position < footer_top_offset) {
$(".main_form_wrapper").addClass('sticky');
} else {
console.log('reached end')
$(".main_form_wrapper").removeClass('sticky');
}
}
});
If anyone can offer some guidance, that would be greatly appreciated!