JQuery autoplay video

前端 未结 3 1539
盖世英雄少女心
盖世英雄少女心 2020-12-17 07:09

Hi I have some very basic html for a video:

3条回答
  •  忘掉有多难
    2020-12-17 07:30

    Here is an example of a video that will cover the whole window and autoplay, on a loop. It's created on demand via JavaScript.

    I needed this for a video that should only load and play when requested, i.e. not on every load of the page. (Hiding the element with display: none; won't do, because the video then still loads even if not displayed.)

    JavaScript

    /**
     * Create the video.
     *
     * An alternative might have been to use an HTML template tag inside the Twig template,
     * to then create an element and append it. But this worked only in Chrome:
     * - in Firefox, `autoplay loop muted` (inside the