Cease the automatic playing of videos that are embedded on certain screen sizes

I am currently designing a website that includes two identical Vimeo videos. One is intended for larger screen resolutions, while the other is meant for resolutions below 1000px. To achieve this, I have placed both videos on the page and used CSS to control their visibility.

However, I encountered an issue with autoplay on page load. When using the display:none; CSS property, the videos are hidden but continue playing in the background.

I have attempted to resolve this using jQuery and Froogaloops, but so far I have been unsuccessful. Here is my current code:

    jQuery(document).ready(function($) {

    var player = $("#82625501");
    froogaloop = $f(player[0].id);
    // Optimization: Store references outside event handler:
    var $window = $(window);

    function checkWidth() {
        var windowsize = $window.width();
        if (windowsize < 1000) {

             froogaloop.api('pause');

        }
        else {
             froogaloop.api('play');
        }
    }
    // Execute on load
    checkWidth();
    // Bind event listener
    $(window).resize(checkWidth);
});

This implementation works only when resizing the screen, not on initial page load. How can I address this issue? Is there a simpler solution available? Thank you in advance!

Answer №1

To adjust the autoplay setting, refer to Vimeo's embed API and change the parameter to '1' as shown below:

<iframe src="//player.vimeo.com/video/82527075?autoplay=1" width="500" height="209" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p><a href="http://vimeo.com/82527075">The Awareness</a> from <a href="http://vimeo.com/user2354244">Henry</a> on <a href="https://vimeo.com">Vimeo</a>.</p>

Adding ?autoplay=1 to the src url will enable autoplay, but this may not work on all mobile devices due to data consumption concerns.

You can either manually add this parameter or select autoplay when obtaining the embed code from Vimeo by using the show options menu.

If you want to disable the video, you can hide it with CSS (display: none;). In my Firefox test, the video stopped playing once it was hidden past a certain point.

For a hard stop when videos are not visible, you can refer to this helpful question.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The group management options are mysteriously missing from Django's admin page

After deploying a Django web app, I encountered issues accessing the admin page. I expected to see the interface for adding or removing users from a specific group, but it was not displaying as expected. https://i.sstatic.net/5bfUy.png Upon inspecting th ...

Tips for adjusting the height of Bootstrap Mansory columns

Struggling to figure out how to adjust the height of my column to accommodate three elements in each the first and second columns. As a newcomer to design elements, I could really use some guidance. Here's the mock-up I aim to create: https://i.sstat ...

JQueryMobile: Dynamic Creation of Nested Arrays

Recently, I have been delving into JQuerymobile to expand my knowledge and skillset. I created the code snippet below and wanted to confirm if JQueryMobile is able to support this type of functionality. function BooksCategory () { ID = &a ...

"Enhancing user interactivity with Bootstrap popovers using jQuery

Bootstrap's popover is giving me trouble when I try to insert it using jquery append. Take a look at this example http://jsfiddle.net/mT76T/300/! Shouldn't this be working as expected? ...

Increasing the size of text in CSS with the use of ":hover" and then causing it to return to its original smaller size

Allow me to explain my goal here. I have text displayed on my website that I would like to enlarge when the user hovers over it and then shrink back down when they move their cursor away. The issue I'm facing is that after enlarging the text using t ...

The comparison between createElement() and AJAX response

Currently, my website has a login form that updates the page with user data through AJAX after successful login. To maintain semantic integrity, I use JavaScript to remove the login form from the page once the user is logged in. However, when the user lo ...

Scrolling feature is not effective in lower resolutions

At resolutions lower than 1024x768, the browser scroll is not functioning correctly. If you look closely, you will see that when the resolution is smaller, the purple stripe is not fully visible. I also observed that the body is positioned at the top, whi ...

Interactive Image Effects with Hover using HTML and JavaScript

I have observed that the transform works fine, but there is a slight issue when initially hovering or touching the image. After the first touch or hover, everything works great. Any assistance on fixing this minor issue would be greatly appreciated. Thank ...

Enhancing CSS and HTML: Increasing the Border Color of Dropdown Menus and Utilizing Multiple Words per Dropdown Item

https://i.sstatic.net/ZI8Ch.png CODE div.box { display: block; text-align: center; margin: auto; z-index: 5 } #navMenu { margin: 0; padding: 0; } #navMenu ul { margin: 0; padding: 0; line-height: 30px; } #navMenu li { margin: 0; padding: 0; list- ...

How can I make a recently added row clickable in an HTML table?

I have a table where each row is given the class ".clickablerow". I've set up an onclick function so that when a row is clicked, a dialog box appears allowing me to insert text above or below as a new row. The issue I'm facing is that even though ...

Border-Encased Navigation Menus in Bootstrap 4

I am a beginner with Bootstrap 4 and I'm curious to know if there is a way in Bootstrap 4 to create navbar menus surrounded by borders similar to the design shown in this image. Thank you in advance! ...

Jquery append functionality failing to set value in select element

Recently, I've been working on an MVC project that utilizes PHP, JavaScript, and an Oracle database on the backend. However, I've encountered a perplexing issue that I just can't seem to solve. I have a select element that I'm trying to ...

The functionality of Ajax is limited to a single execution after form submission

I am currently working on developing a login widget that makes use of ajax within the user interface of Wordpress. I have successfully created a form, implemented ajax, and set up a response system. However, I am experiencing an issue where the form only f ...

What is the method to execute jQuery code after the completion of a fade out effect?

I am attempting to fade out a div upon click while also adjusting some CSS properties. The problem I am encountering is that the CSS properties change during the fade out transition, instead of after it has completed. I would like the values to change onc ...

Align text to the right and left side

HTML file: <div id="home"> <b><p class="split-para">java<br><a href="j_temp.html" class="float">temperature converter in terminal</a> <br> <a href="j_palindrom.html" class="float">palindrome checker</a& ...

Discover the value of the textbox within a gridview row that has been checked using Jquery

I'm working with a Gridview that has checkbox and textbox columns. I need to figure out how to retrieve the value of the textbox associated with the checked row. var checkCheckBox = $("#<%=GrdV.ClientID %> [id*=chkOrder]"); $(checkCheckBox).cli ...

Is it possible to send a POST request to the server using a customized

I'm currently facing a challenge in establishing a connection with my server to transmit a POST request in JSON format. The URL for the request varies depending on the specific ID displayed on the template. For example, if I am viewing a "group" with ...

The mysterious result of the <em> tag in a WordPress theme

My new WordPress theme is unexpectedly outputting an <em> tag, even though I haven't used any <em> tags in my theme. This is causing issues and affecting the design. Below is the content of my index.php file: <?php get_header(); ?> ...

Having difficulty transmitting a base64 video via Ajax Post to PHP

While attempting to upload a MP4 video with a size of 16.9 MB via ajax asynchronous post to a PHP file, an error is displayed in the console: POST net::ERR_EMPTY_RESPONSE It seems that the issue is related to the PHP memory_limit setting. When set to 200 ...

Tips for creating a div element that closes on the second click:

On the PC version, I have three blocks that open and close perfectly when clicked. However, on the mobile version, when I click on one block, it opens but does not close unless I click on another block. Additionally, if I click again on the same block th ...