#21 - Notificaciones Toast personalizadas

Muestre cajas de tostadas personalizadas al hacer clic en un elemento

Video Tutorial

Loom
tutorial.mov

Watch the video for step-by-step implementation instructions

The Code

44 lines
Paste this into Webflow
<!-- 馃挋 MEMBERSCRIPT #21 v0.1 馃挋 CUSTOM TOAST BOXES -->
<script>
document.addEventListener("DOMContentLoaded", function() {
 聽const toastTriggers = document.querySelectorAll("[ms-code-toast-trigger]");

 聽toastTriggers.forEach(trigger => {
 聽 聽trigger.addEventListener("click", function() {
 聽 聽 聽const triggerId = trigger.getAttribute("ms-code-toast-trigger");
 聽 聽 聽const toastBox = document.querySelector(`[ms-code-toast-box="${triggerId}"]`);

 聽 聽 聽if (toastBox) {
 聽 聽 聽 聽const fadeInDuration = 200;
 聽 聽 聽 聽const fadeOutDuration = 200;
 聽 聽 聽 聽const staticDuration = 2000;
 聽 聽 聽 聽const totalDuration = fadeInDuration + staticDuration + fadeOutDuration;

 聽 聽 聽 聽toastBox.style.opacity = "number0";
 聽 聽 聽 聽toastBox.style.display = "block";

 聽 聽 聽 聽let currentTime = 0;

 聽 聽 聽 聽const fade = function() {
 聽 聽 聽 聽 聽currentTime += 10;
 聽 聽 聽 聽 聽const opacity = currentTime < fadeInDuration
 聽 聽 聽 聽 聽 聽? currentTime / fadeInDuration
 聽 聽 聽 聽 聽 聽: currentTime < fadeInDuration + staticDuration
 聽 聽 聽 聽 聽 聽 聽? 1
 聽 聽 聽 聽 聽 聽 聽: 1 - (currentTime - fadeInDuration - staticDuration) / fadeOutDuration;

 聽 聽 聽 聽 聽toastBox.style.opacity = opacity;

 聽 聽 聽 聽 聽if (currentTime < totalDuration) {
 聽 聽 聽 聽 聽 聽setTimeout(fade, 10);
 聽 聽 聽 聽 聽} else {
 聽 聽 聽 聽 聽 聽toastBox.style.display = "none";
 聽 聽 聽 聽 聽}
 聽 聽 聽 聽};

 聽 聽 聽 聽fade();
 聽 聽 聽}
 聽 聽});
 聽});
});
</script>

Script Info

Versionv0.1
PublishedNov 11, 2025
Last UpdatedNov 11, 2025

Need Help?

Join our Slack community for support, questions, and script requests.

Join Slack Community
Back to All Scripts

Related Scripts

More scripts in Conditional Visibility