Jump to content

How can I hide an audio block on my wesbite

Recommended Posts

Hey,

How can I embed sound on my homepage and hide the audio block so it can't be seen?

I have used the below code in the advanced settings tab linked to my homepage, and it works at removing the block on the back end, but not for the live site on computer and IOS. 

<script>
window.addEventListener('DOMContentLoaded', function() { //wait for document load
    var audio = document.querySelector('.sqs-audio-embed'); //select the audio block
    if (!Y.UA.mobile) { //it is not mobile
        var checkOnScroll = function() {
            if (window.pageYOffset > 200) {
                audio.pause();
            } else {
                audio.play();
            }
        };
        if (audio) {
            var url = audio.getAttribute('data-url'); //get the audio src
            Y.one(audio).ancestor('.sqs-block-audio').setStyle('display','none');
            audio = new Audio(url);
            window.addEventListener('scroll', checkOnScroll); //listen for window scroll and toggle audio state
            checkOnScroll();
        }
    }
})
</script>

Any tips would be greatly appreciated. 

Thanks!

Link to comment
  • Replies 5
  • Views 2.6k
  • Created
  • Last Reply

Top Posters In This Topic

On 8/31/2023 at 9:52 PM, MissCocoBelle said:

Hi, 

I have removed the audio button for now as I don't like the way it looks.

https://www.misscocobelle.com/

You can add a test code, add audio & code there, then share url, we can check easier

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
  • 3 months later...

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.