Featured image of post How to Build Sticky Bottom Banner with jQuery (No Footer Overlap)

How to Build Sticky Bottom Banner with jQuery (No Footer Overlap)

Build sticky bottom banner with jQuery that stays within container boundaries. Prevent footer overlap and implement responsive design with production code.

Have you ever built a website where you needed a call-to-action button or promotional banner to stay visible at the bottom of the screen, but then realized it was covering up your footer or other important content? I know I have, and it’s frustrating.

When I first started implementing bottom sticky banners, I made the classic mistake of using position: fixed; bottom: 0; and calling it done. The banner worked great… until users scrolled to the bottom of the page and couldn’t see my contact information or legal links because the banner was sitting right on top of them. That’s when I realized I needed a smarter approach—one that would keep the banner visible only within specific content areas.

After working on dozens of e-commerce sites and landing pages, I discovered the perfect solution: a sticky bottom banner that respects container boundaries. In this guide, I’ll walk you through exactly how to build this with jQuery, from the core positioning logic to responsive design considerations.

We’ll cover everything from basic container-based positioning to advanced scroll optimization techniques, with practical code examples you can implement immediately.


What is a Sticky Bottom Banner?

A sticky bottom banner is a UI element that remains fixed at the bottom of the viewport while users scroll, but intelligently switches to absolute positioning when it reaches the end of its designated container. This prevents the banner from overlapping footer content or other page sections, creating a seamless user experience.


Why Container-Based Sticky Banners Matter

In my experience working on production websites, I’ve seen too many sites where floating elements create a poor user experience. Here’s why you need smarter positioning:

Real-world scenarios where this matters:

  • E-commerce product pages: Your “Add to Cart” button should disappear when users reach related products
  • Blog articles: Social sharing buttons shouldn’t cover your author bio or comments section
  • Landing pages: CTA banners need to respect form sections and testimonials

The traditional position: fixed approach fails because it doesn’t consider content hierarchy. Users end up frustrated when they can’t access important information that’s hidden behind persistent banners.


How Container-Based Positioning Works

The magic happens through dynamic position switching. Instead of always using position: fixed, we calculate scroll positions in real-time and switch between fixed and absolute positioning based on the user’s viewport position relative to our container.

The calculation logic:

  1. Track container boundaries: We measure the container’s top and bottom positions
  2. Monitor viewport position: We calculate where the user’s screen bottom currently sits
  3. Smart position switching: When the viewport bottom exceeds the container bottom, we switch from fixed to absolute

This creates a banner that “sticks” to the container rather than the entire page.



Building Your Sticky Bottom Banner: Step-by-Step

Step 1: Create the HTML Foundation

Start with a clean, semantic structure that clearly defines your container and banner elements:

1
2
3
4
5
6
<div class="container">
    <div class="bottom_sticky">
        This banner stays fixed only within the container!
    </div>
</div>
<footer></footer>

The key here is the parent-child relationship. The container acts as our boundary, while the banner element will move between different positioning modes.


Step 2: Style with Purpose-Built CSS

Set up your styles to support dynamic positioning changes:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
.container { 
    position: relative; 
    min-height: 150vh; 
    border: 2px solid #ddd; 
    margin: 20px auto; 
    max-width: 800px; 
    overflow: hidden; 
}
.bottom_sticky { 
    position: fixed; 
    right: 0; 
    bottom: 30px; 
    left: 50%; 
    width: 500px;
    height: 60px; 
    max-width: 100%;
    transform: translate(-50%, 0);
    background: #007bff; 
    color: white; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-weight: bold; 
    z-index: 100; 
}
footer { 
    height: 80px; 
    background: #333; 
}

Critical CSS principles:

  • Container needs position: relative to serve as the positioning context
  • Banner starts with position: fixed (jQuery will change this dynamically)
  • z-index: 100 ensures the banner appears above other content
  • transform: translate(-50%, 0) centers the banner horizontally

Step 3: Implement the Complete jQuery Solution

Here’s the production-ready code that handles all the positioning logic:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Initialize bottom sticky banner functionality
function initBottomSticky() {
    const $apply = $('.bottom_sticky');
    const $wrap = $('.container');
    let rafId = null;
    
    // Function to update the position of the floating banner
    function updatePosition() {
        if ($apply.length && $wrap.length) {
            const wrapOffset = $wrap.offset().top;
            const wrapHeight = $wrap.outerHeight();
            const scrollPosition = $(window).scrollTop();
            const windowHeight = window.innerHeight;
            const wrapBottom = wrapOffset + wrapHeight;
            const currentBottom = scrollPosition + windowHeight;
            
            // Change position property based on container boundaries
            const cssProperties = {
                'position': currentBottom >= wrapBottom ? 'absolute' : 'fixed',
            };
            $apply.css(cssProperties);
        }
    }
    
    // Function to add appropriate padding to the container
    function updatePadding() {
        if ($apply.length && $wrap.length) {
            const windowWidth = $(window).width();
            const paddingValue = windowWidth >= 768 ? 80 : 40; // Desktop/mobile distinction
            const applyHeight = $apply.outerHeight() + paddingValue;
            $wrap.css('padding-bottom', applyHeight + 'px');
        }
    }
    
    // Performance-optimized scroll update function
    function optimizedUpdate() {
        if (rafId) {
            cancelAnimationFrame(rafId);
        }
        rafId = requestAnimationFrame(updatePosition);
    }
    
    // Scroll event (optimized with requestAnimationFrame)
    $(window).on('scroll', optimizedUpdate);
    
    // Resize event handling
    $(window).on('resize', function() {
        updatePadding();
        updatePosition();
    });

    // Page load event handling
    $(window).on('load', function() {
        updatePadding();
        updatePosition();
    });
}

// Execute after DOM is ready
$(document).ready(function() {
    initBottomSticky();
});


Breaking Down the Core Logic

Let me walk you through the key components that make this bottom floating banner work reliably.


The Position Calculation Engine

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
function updatePosition() {
    if ($apply.length && $wrap.length) {
        const wrapOffset = $wrap.offset().top; // Container top position
        const wrapHeight = $wrap.outerHeight(); // Container height
        const scrollPosition = $(window).scrollTop(); // Current scroll position
        const windowHeight = window.innerHeight; // Viewport height
        const wrapBottom = wrapOffset + wrapHeight; // Container bottom position
        const currentBottom = scrollPosition + windowHeight; // Viewport bottom position
        
        // Change position property based on container boundaries
        const cssProperties = {
            'position': currentBottom >= wrapBottom ? 'absolute' : 'fixed',
        };
        $apply.css(cssProperties);
    }
}

How the magic happens:

  • wrapOffset + wrapHeight: Calculates the absolute bottom position of our container
  • scrollPosition + windowHeight: Determines where the user’s viewport bottom currently sits
  • When viewport bottom exceeds container bottom → switch to absolute positioning
  • Otherwise → maintain fixed positioning for bottom viewport attachment

Smart Responsive Padding Management

1
2
3
4
5
6
7
8
function updatePadding() {
    if ($apply.length && $wrap.length) {
        const windowWidth = $(window).width();
        const paddingValue = windowWidth >= 768 ? 80 : 40; // Desktop/mobile breakpoint
        const applyHeight = $apply.outerHeight() + paddingValue;
        $wrap.css('padding-bottom', applyHeight + 'px');
    }
}

Why padding management matters:

  • Prevents the sticky banner from covering container content when it switches to absolute positioning
  • Responsive values ensure proper spacing on both desktop (80px) and mobile (40px) devices
  • Dynamic height calculation accommodates different banner sizes

Performance-Optimized Scroll Handling

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// Performance-optimized scroll update function
function optimizedUpdate() {
    if (rafId) {
        cancelAnimationFrame(rafId);
    }
    rafId = requestAnimationFrame(updatePosition);
}

// Scroll event (optimized with requestAnimationFrame)
$(window).on('scroll', optimizedUpdate);

Performance benefits:

  • requestAnimationFrame: Syncs with browser refresh rate (typically 60fps) for smooth animations
  • Prevents the janky scrolling behavior common on mobile devices
  • Automatically pauses when the tab is inactive, saving battery life
  • cancelAnimationFrame: Prevents overlapping executions for consistent performance

Advanced Implementation Techniques

Understanding the Position Switch Logic

The core of our container-based sticky banner lies in this decision matrix:

ConditionPosition ValueBehavior
currentBottom < wrapBottomfixedBanner sticks to viewport bottom
currentBottom >= wrapBottomabsoluteBanner locks within container
Resize eventRecalculateUpdate all measurements

The decision criteria:

  • When users scroll within the container area: banner stays fixed to screen bottom
  • When users scroll past the container: banner becomes absolute and stays with container content

Production Best Practices

From my experience implementing this across dozens of client projects, here are the essential best practices:

  1. Prevent Initial Flash: Set visibility: hidden in CSS, then show with JavaScript after calculations
  2. Mobile Safari Compatibility: Use window.innerHeight for accurate viewport measurements (handles address bar changes)
  3. Performance First: Always use requestAnimationFrame for scroll events—never bind directly
  4. Accessibility Considerations: Ensure keyboard navigation still works properly with the floating banner


Frequently Asked Questions

The key is in our dynamic positioning logic. When users scroll past your container, the banner automatically switches from fixed to absolute positioning, ensuring it never covers footer content. The updatePadding() function also adds appropriate bottom spacing to prevent any overlap scenarios.


What’s the best way to customize the banner design?

Focus on modifying visual properties in the .bottom_sticky CSS class: background, color, border-radius, box-shadow, and font-family.


How do I handle different screen sizes effectively?

Our solution includes responsive padding (paddingValue) that adjusts based on screen width. For more complex responsive behavior, consider adding CSS media queries for the banner width, height, and font sizes while keeping the JavaScript positioning logic intact.


Is this technique SEO-friendly?

Yes, because the banner is implemented with progressive enhancement. The content remains accessible to search engines since the banner is added via JavaScript after the page content loads. Screen readers and crawlers can access all your content without interference.


What’s Next for Your Sticky Banner Implementation?

Now that you understand how to create intelligent sticky bottom banners, here are some practical next steps:

Immediate Actions:

  • Try implementing this on a simple landing page with a newsletter signup banner
  • Test the behavior on mobile devices to see how smooth the transitions feel
  • Experiment with different banner heights and padding values

Advanced Enhancements:

  • Add CSS transitions for smoother position changes
  • Implement show/hide animations based on scroll direction
  • Create A/B testing variations to measure conversion improvements
  • Consider adding close buttons for better user control

The beauty of this container-based approach is that it scales to any design need while maintaining excellent user experience. Whether you’re building e-commerce sites, blogs, or marketing pages, this technique ensures your important messages stay visible without becoming intrusive.

What kind of sticky banner are you planning to implement? I’d love to hear about your specific use case and any creative adaptations you come up with! Drop a comment below and let’s discuss how to make this work perfectly for your project.


Hugo로 만듦
JimmyStack 테마 사용 중