Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
With the following code I managed to make the icon not go over the footer area, but instead remaing in the body.
This was requested by some clients, so here it is:
(function($) {
Drupal.behaviors.scroll_top_top_not_over_footer = {
attach: function (context, settings) {
$(document).scroll(function() {
if($('#back-top').offset().top + $('#back-top').height() >= $('footer').offset().top - 10)
$('#back-top').css('bottom', $('footer').height() + 30);
$('#back-top').css('transition', 'bottom 2s');
if($(document).scrollTop() + window.innerHeight < $('footer').offset().top)
$('#back-top').css('bottom', '10px'); // restore when you scroll up
});
}
};
})(jQuery);
Comments
Comment #2
bserem CreditAttribution: bserem at zehnplus commented