Sticky buy bar on mobile
Hypothesis. On phones the buy button scrolls out of view within a second. Keeping it on screen will lift add-to-cart rate.
Approach. The variation clones the existing buy button into a fixed bar at the bottom of the screen, so the click handler and tracking the store already has keep working. It only runs under 768px, waits for the button to exist, and does nothing if it is missing.
- No libraries: 20 lines of plain JavaScript and a 6-line stylesheet.
- Backs out cleanly if the buy button never appears, so the control is never broken.
- Reuses the store's click handler instead of re-implementing checkout or tracking.
// Variation B: sticky buy bar on mobile
if (window.innerWidth > 768) return;
waitFor('#buy', function (buy) {
if (document.querySelector('.lc-sticky-buy')) return;
var bar = document.createElement('div');
bar.className = 'lc-sticky-buy';
bar.appendChild(buy.cloneNode(true));
document.body.appendChild(bar);
// Hide the bar while the real button is on screen.
new IntersectionObserver(function (entries) {
bar.hidden = entries[0].isIntersecting;
}).observe(buy);
// The clone keeps the store's own click handler via event delegation.
bar.addEventListener('click', function () { buy.click(); });
});| QA check | Desktop | Mobile |
|---|---|---|
| Chrome, Firefox, Edge (desktop) | Not shown, by design | — |
| Safari (macOS) | Not shown, by design | — |
| Safari (iPhone 13, 15) | — | Pass |
| Chrome (Pixel 7, Galaxy S23) | — | Pass |
| Flicker / layout shift on slow 3G | None | None |
| Survives SPA navigation | Pass | Pass |
| Goals: purchase fires once | Pass | Pass |
| Console errors | 0 | 0 |