0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

モーダルで画像・動画を表示!「fancybox3」を使ってみた

Last updated at Posted at 2021-01-23

自身のポートフォリオ作品(画像)を、ページ遷移ではなくモーダル表示にしたかったので、探してみたところ、「Fancybox3」というモバイルも対応している超優れものを見つけたので、さっそく実装してみました。

◆Fancybox3のサイトはこちら
https://fancyapps.com/fancybox/3/

①ダウンロード

まずは「fancyBox3」のサイトから、データをダウンロードします。
ダウンロード後、自身のローカルリポジトリ内へ読み込み。

ちなみに、

HTML
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />
<script src="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>

こちらをHTML内に記述しても実装できました。

②HTMLを記述

HTML
<a data-fancybox="gallery" href="big_1.jpg"><img src="small_1.jpg"></a>
<a data-fancybox="gallery" href="big_2.jpg"><img src="small_2.jpg"></a>

こちらをHTML内に記述したら、なんということでしょう、、あっという間に実装されました!

私はモーダルを表示させた後にキャプションをつけたかったので、

HTML
<a data-fancybox="gallery" href="big_1.jpg" data-caption="****"><img src="small_1.jpg"></a>

data-captionをつけてあげたら、表示されました◎

参考サイト様

モーダルで閲覧できるギャラリーを実装するのにfancyBox3が便利過ぎる。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?