LoginSignup
2
2

More than 3 years have passed since last update.

【HTML,CSS,JavaScript】動画をパララックスする

Last updated at Posted at 2020-02-10

写真をパララックスにするプラグインの紹介などは結構あったのですが、動画は意外となかったのでメモ。
動画の埋め込み自体あんまり使うことないんですが、どうしてもやらなきゃいけない&時間かけられない時にさくっと実装できます。

動画をパララックスさせたい

1) 下記リンク先 backgroundVideo にアクセス、distフォルダ内のjsのどちらかを読み込ませる。
https://github.com/linnett/backgroundVideo

2) 任意のクラスをVIDEOタグにつけて、以下のようなJavaScriptの記述をする。

index.html
<video class="bv-video"></video>

<script>
new BackgroundVideo('.bv-video', {
  src: [
    //動画保存先のパス
    'MY/EXAMPLE/PATH/SAMPLE.mp4',
    'MY/EXAMPLE/PATH/SAMPLE.webm'
  ]
});
</script>

3) 高さを上書きしたい場合は、 .bv-video-wrap クラスに !important をつけて高さを上書きする。

style.css
.bv-video-wrap {
   height: 500px !important;
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2