LoginSignup
4
5

More than 3 years have passed since last update.

Railsでhamlファイルに動画を埋めこむ

Last updated at Posted at 2020-03-15

今回はhamlファイル内に動画を埋め込む方法をご紹介します!
背景に動画を流したいときにオススメです。

publicフォルダにvideosフォルダを作成

上記で作成したフォルダ内にあらかじめ用意した動画ファイルを保存

今回は拡張子mp4のファイル、sample.mp4を用います。

hamlファイルに以下を記述

○○.html.haml
= video_tag("/videos/sample.mp4", autoplay: true, loop: true, muted: true, class: 'content__box__video')

video_tag

ビデオタグを用いて動画ファイルを呼び出します。

/videos/sample.mp4

参照先のフォルダを指定します。
publicフォルダは指定する必要ありません。

autoplay: true

ページ更新時に自動再生されます。

loop: true

繰り返し再生になります。

muted: true

無音になります。

class: 'content__box__video'

クラス名をつけてscssファイルでレイアウトを調整します。

参考

【videoタグ】HTMLで動画を埋め込む方法を徹底まとめ

→ 投稿した動画を表示するにはまた別の方法が必要なので次回ご紹介します!

4
5
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
4
5