First-Visit Announcement Bar
A tiny announcement bar that only shows on a visitor’s first visit using
localStorage. Great for “New here?” messages, promos or important
updates without nagging regulars. No cookies, no frameworks, just a small
drop-in snippet.
How it works:
- Shows a fixed bar at the top on the visitor’s first page view.
- When they click “× Close”, the bar fades out and sets a flag in
localStorage. - On future visits, the script sees the flag and never shows the bar again.
- You can change the text, link, colors and storage key in one place.
Install: Paste the snippet right before </body> on your page
(ideally in a common footer include if you have one).
<!-- First-Visit Announcement Bar (VibeScriptz) -->
<div
id="vs-announce-bar"
class="vs-announce-bar"
data-vs-key="vs_announce_seen_main"
>
<div class="vs-announce-inner">
<span class="vs-announce-text">
New here? 👋 Check out our most popular script:
<a href="/script/dark-mode-toggle-with-local-storage-no-frameworks/">
Dark Mode Toggle
</a>
</span>
<button class="vs-announce-close" type="button" aria-label="Close">
×
</button>
</div>
</div>
<style>
/* --- First-Visit Announcement Bar (no frameworks, no cookies) --- */
.vs-announce-bar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 9999;
background: #111;
color: #f5f5f5;
transform: translateY(-100%);
opacity: 0;
transition: transform 0.25s ease-out, opacity 0.25s ease-out;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
sans-serif;
font-size: 14px;
}
.vs-announce-visible {
transform: translateY(0);
opacity: 1;
}
.vs-announce-hiding {
opacity: 0;
}
.vs-announce-inner {
max-width: 1100px;
margin: 0 auto;
padding: 8px 12px;
display: flex;
align-items: center;
gap: 10px;
}
.vs-announce-text {
flex: 1;
line-height: 1.4;
}
.vs-announce-text a {
color: #ffd86b;
text-decoration: underline;
}
.vs-announce-text a:hover {
color: #ffe9a6;
}
.vs-announce-close {
border: 0;
background: #444;
color: #fff;
cursor: pointer;
border-radius: 999px;
width: 24px;
height: 24px;
line-height: 24px;
padding: 0;
text-align: center;
font-size: 16px;
}
.vs-announce-close:hover {
background: #666;
}
/* Slightly smaller on narrow screens */
@media (max-width: 600px) {
.vs-announce-inner {
padding: 6px 10px;
font-size: 13px;
}
}
</style>
<script>
/*
* First-Visit Announcement Bar
* - Uses localStorage only (no cookies)
* - Change data-vs-key if you want a separate bar per campaign
*/
(function () {
var bar = document.getElementById("vs-announce-bar");
if (!bar) return;
var storageKey = bar.getAttribute("data-vs-key") || "vs_announce_seen";
// If we've already seen this announcement, remove the bar and bail
try {
if (window.localStorage && localStorage.getItem(storageKey) === "1") {
bar.parentNode.removeChild(bar);
return;
}
} catch (e) {
// localStorage might be blocked; fail silently and just show the bar
}
// Show bar
bar.classList.add("vs-announce-visible");
function hideBar() {
bar.classList.remove("vs-announce-visible");
bar.classList.add("vs-announce-hiding");
// Remove from DOM after fade
setTimeout(function () {
if (bar && bar.parentNode) {
bar.parentNode.removeChild(bar);
}
}, 300);
// Remember dismissal
try {
if (window.localStorage) {
localStorage.setItem(storageKey, "1");
}
} catch (e) {}
}
// Close on button click
bar.addEventListener("click", function (evt) {
if (
evt.target.classList.contains("vs-announce-close") ||
evt.target.closest(".vs-announce-close")
) {
hideBar();
}
});
})();
</script>
Customize it:
- Change the text and link inside
.vs-announce-text. - Tweak colors in the CSS (
background: #111;, link colors, etc.). - Change
data-vs-keyif you want a different bar for a new promo. - To make it show again for yourself, clear
localStoragefor this site or use a private window.