Creating a script in Webflow to close modals with embedded videos when the .close-modal button is clicked involves using custom code within the Webflow Designer.
Sample steps:
loading="lazy" may be useful).
document.querySelectorAll('.close-modal').forEach(button => {
button.addEventListener('click', function() {
const modal = this.closest('.modal');
const video = modal.querySelector('video');
if (video) {
video.pause();
video.currentTime = 0;
}
modal.style.display = 'none'; // or apply a class to hide
});
});
To close modals with embedded videos when the .close-modal button is clicked in Webflow, you must use a custom script that pauses the video and hides the modal on click. Add this script to your project’s custom code section, ensuring it identifies video elements and attaches the necessary event listeners accurately.