Socket
Socket
Sign inDemoInstall

@cleverage/responsive-video-background

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @cleverage/responsive-video-background

A JavaScript library to help build components with responsive video and/or image background


Version published
Maintainers
1
Install size
9.08 kB
Created

Readme

Source

<responsive-video-background /> Web Component

npm npm GitHub

A Web Component that helps responsively using a video as the background of a content block.

The video usage can be restricted to large viewports, with an image fallback on thinner ones.

Examples

See on https://cleverage.github.io/responsive-video-background/

Usage

Syntax

The Web Component's configuration is done with attributes:

<style>
…inline CSS styles for the component, to prevent layout shifts
</style>
<responsive-video-background
    class="…"
    webm="video.webm"
    mp4="video.mp4"
    poster="video-poster.jpg"
    fallback="not-responsive-image.jpg"
    srcset="image-320.jpg 320w, image-640.jpg 640w, image-1024.jpg 1024w"
    sizes="calc(100vh - 2rem)"
    breakpoint="48rem">
  Some content…
</responsive-video-background>

API

AttributeDescriptionExample
webmURL to the WebM version of the videohttps://example.com/path/to/video.webm
mp4URL to the MP4 version of the videohttps://example.com/path/to/video.mp4
posterURL to the video's poster image (should be the first frame)https://example.com/path/to/video-poster.jpg
fallbackURL to the fallback image, for the src attributehttps://example.com/path/to/image-fallback.jpg
srcsetValue of the srcset attribute for the responsive imagehttps://example.com/path/to/image-320px.jpg 320w, https://example.com/path/to/image-850px.jpg 850w, https://example.com/path/to/image-1600px.jpg 1600w
sizesvalue of the sizes attribute for the responsive imagecalc(100vh - 2rem)
breakpointViewport width breakpoint, if there should be an image on thin viewports and a video on larger viewports48rem

If the srcset option is set, these other ones are mandatory:

  • webm and/or mp4
  • fallback
  • sizes

If the breakpoint option is set, these other ones are mandatory:

  • webm and/or mp4
  • fallback
  • srcset
  • sizes

FAQ

Why isn't the image switching to a video when the viewport becomes larger? : This is not a bug. The idea is to prevent a strong visual change when the user changes the viewport, either by resizing the browser, or rotating the device.

Keywords

FAQs

Last updated on 07 Jul 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc