Jump to content

[Share] Pause background video on button press

Recommended Posts

Posted

If you have a section with background video and a button like this. You want: If users click Pause Video button >> Pause section background video.

If it doesn't work, you can send link to page where you use Video, I will check again.

#1. Find ID of Button & ID of Video Section.
In my example, we will have:

  • Button ID: #block-yui_3_17_2_1_1732588943338_11548
  • Section ID: section[data-section-id="674535b561275a62ba933fcf"]

image.png.49862279fab15ebb94761cbffe8ff38e.png

#2. Use this code to Code Injection - Footer (or Page Header Injection)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
    $('#block-yui_3_17_2_1_1732588943338_11548').click(function() {
        const video = $('section[data-section-id="674535b561275a62ba933fcf"] video')[0];
        
        if (video.paused) {
            video.play(); 
        } else {
            video.pause(); 
        }
    });
});
</script>

image.png.0e79da5e583d110549d7e42bfdea6b89.png

#3. Note: Make sure you disable "Open in New Tab" option in Button

image.png.061c63e5c6f358fb1bfc1eb4fc489bc3.png

#4. Remember to replace ID in the code

image.thumb.png.7b94e772dd1e989a40a37d8f56baeb3b.png

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!)

  • Replies 0
  • Views 63
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

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.