Jump to content

Audio File in Lightbox on Mobile, Keeps Playing After File Closed

Recommended Posts

I'm using the Lightbox Anything plugin from Sqsp Themes to play a collection of audio files. 

My issue is on mobile. I. using a script found in the Forum to allowed the audio file to play in the same page on mobile, but when I close the lightbox, the audio continues to play. Desktop is fine. 

Site: whalingcommonground-cms.squarespace.com/stories-from-the-collection 
Pass: nbwm2022

This is the thread where I found the audio code, followed by the specific code I'm using. There are two other codes offered within this thread, but they also result in the audio continuing to play. 

Can anyone provide some assistance to end the audio when the lightbox is closed? 

Thank you!

Link to comment

The developer shared this fix and I'm posting here in case anyone finds it helpful. Instructions were to place this before the plugin code. 🙂

function lightboxStopAudioPlayer() {
const button = document.querySelector('.c-lightbox__close');
const stage = document.querySelector('.c-lightbox__stage');
function pause() {
const pauseButton = document.querySelector('.c-lightbox .pause-button');
if (pauseButton) pauseButton.click();
<div data-lightbox-code-injection>
<script>setTimeout(lightboxStopAudioPlayer, 1000)</script>


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.