Start playing videos as they are shown or enter the viewport.
The Video component offers two advanced functions for videos. First, it allows you to pause a video whenever it’s hidden with CSS and resume playing once it becomes visible again. In addition, the video can pause when it’s outside the viewport and start playing when entering it.
Secondly, it allows you to mute YouTube and Vimeo videos, which is often needed if they are used as the background of a section.
For example, the Slideshow, Lightbox and Cover components inherit and make use of both functions.
To apply this component, add the data-uk-video attribute to a <video> element. The video will be paused whenever it’s hidden with CSS and resume once it becomes visible again.
There are two autoplay options to play the video. Just add the autoplay option to the data-uk-video attribute and apply one of these values.
| Values | Description |
|---|---|
inview | Play video when it enters the viewport and pause it again when it leaves the viewport. |
hover | Play video when the mouse hovers the video and pause it again when the mouse leaves the hover. |
To mute YouTube or Vimeo videos by default, add the data-uk-video="automute: true" attribute to the <iframe> element.
Any of these options can be applied to the component attribute. Separate multiple options with a semicolon. Learn more
| Option | Value | Default | Description |
|---|---|---|---|
autoplay | Boolean, String | true | The video automatically plays/pauses as it’s visible/hidden on the page. Additionally, the video can play when its in the viewport or hovered with the mouse (inview, hover). |
automute | Boolean | false | Automatically mute YouTube or Vimeo videos. |
autoplay is the Primary option, and its key may be omitted if it’s the only option in the attribute value.
Learn more about JavaScript components.