I’m working on a custom top banner (announcement bar) for my funnel — something like a “50% discount - today only” message that sticks to the top of the page.
Make the banner dismissible — with a little “X” button When clicked, the banner should disappear (ideally with smooth animation)
If anyone has done something like this or has a clean snippet to share — I’d love to see how you tackled it!
<script>
document.addEventListener('DOMContentLoaded', function () {
const banner = document.querySelector('.custom-banner');
if (banner) {
// Create close button
const closeBtn = document.createElement('button');
closeBtn.innerHTML = '×';
closeBtn.className = 'close-banner';
// Append to banner
banner.appendChild(closeBtn);
// Add click handler
closeBtn.addEventListener('click', function () {
banner.classList.add('hide');
});
}
});
</script>
That’s it! Now your banner will have a close (×) button added automatically using JavaScript, and clicking it will dismiss the banner with a smooth animation.
Let me know if you want it to stay hidden even after page reload — I can help with that too.