"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Prevent Fixed Objects from Overlapping Footers?

How to Prevent Fixed Objects from Overlapping Footers?

Published on 2024-11-25
Browse:140

How to Prevent Fixed Objects from Overlapping Footers?

Fixing Fixed Objects at Page Footers

The common issue of fixed objects scrolling over footers has a simple solution. For instance, let's consider a fixed "share" box in the bottom left corner of the screen. To prevent it from overlapping the footer, we'll stop it about 10px above the footer.

First, we need to determine the box's proximity to the footer each time the page is scrolled:

$(document).scroll(function() {
    checkOffset();
});

If the box gets too close to the footer (i.e., within 10px), we'll change its position to absolute:

function checkOffset() {
    if($('#social-float').offset().top   $('#social-float').height() 
                                           >= $('#footer').offset().top - 10)
        $('#social-float').css('position', 'absolute');
    if($(document).scrollTop()   window.innerHeight 

Note that the parent of the #social-float should be a sibling of the footer in the HTML structure.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3