A Bootstrap 5 free shipping announcement bar that rotates short promo messages above your store header, with pause, previous, next and close buttons. Use it for free shipping thresholds, return policies and discount codes on e-commerce sites.
How it works
The root .fsb-root holds the aside.fsb-bar and, for the demo only, a store navbar and hero. Inside the bar, .fsb-viewport contains one p.fsb-msg per message. The viewport is a CSS grid and every message sits in the same grid cell, so the bar always keeps the height of the longest message and the page below never jumps. Inactive messages carry the hidden attribute, which the CSS turns into visibility: hidden.
On DOMContentLoaded the script starts a timer for every .fsb-root. Every data-fsb-interval milliseconds it moves is-active to the next message, which slides in with the fsb-in keyframes, and restarts the thin .fsb-progress line at the bottom of the bar. The timer stops while the pointer or keyboard focus is inside the bar and resumes when they leave. .fsb-prev and .fsb-next step through the messages manually, and .fsb-pause stops the rotation until it is pressed again.
.fsb-close collapses the bar with a short height transition, hides it and stores the dismissal in sessionStorage under the data-fsb-key value, so the bar stays closed for the rest of the visit. When storage is blocked, the bar returns on the next page load.
Customization
--fsb-bg,--fsb-textand--fsb-accenton.fsb-rootinstyle.css: recolor the bar, its text, the icons, links and the progress line.--fsb-heighton.fsb-root: set the minimum height of the bar.data-fsb-interval="5000"on.fsb-root: change how long each message stays visible, in milliseconds.data-fsb-keyon.fsb-root: use a new key (for example per campaign) so visitors who closed an older bar see the new one.- Add or remove
p.fsb-msgelements in.fsb-viewport: the script counts them automatically; give every message except the first thehiddenattribute. .fsb-codeinside a message: highlights a coupon code with a dashed accent border.- Remove the
.fsb-demo-navand.fsb-demo-heroblocks and--fsb-demo-bg: they only show the bar in context.
Use cases
- Online stores: rotating messages promote free shipping, returns and coupon codes
- Sale campaigns: a progress line shows when the next message appears
- Site-wide notices: pause and arrow controls let visitors read at their own pace
- Ecommerce headers: a dismiss button hides the bar once seen
Accessibility
The bar is an aside labelled "Store announcements". Automatic rotation keeps aria-live="off" on .fsb-viewport, so screen readers are not interrupted every few seconds; manual navigation and the paused state switch it to polite. The pause button uses aria-pressed and an aria-label that changes between "Pause announcements" and "Play announcements", which satisfies the WCAG requirement to stop moving content. All controls are real buttons with visible focus outlines. After closing, focus moves to the next focusable element on the page. With prefers-reduced-motion: reduce the slide-in, progress line and collapse animations are turned off.
Usage notes
Requires Bootstrap 5 and Bootstrap Icons. Place .fsb-root (without the demo blocks) at the top of the body. Several bars work independently. Below the sm breakpoint only the pause and close buttons are shown.