remodal.js で手軽にモーダルウィンドウを実装する
===============================================
remodal.jsとは
--------------
簡単にレスポンシブで軽くて早いモーダル機能をを実装できる!
.. figure:: ../image/remodal.png
:alt:
使い方
------
Step1 ファイルを読み込む
~~~~~~~~~~~~~~~~~~~~~~~~
`Github `__
のdist以下のファイルを読み込む
- remodel.min.js
- remodel.css
- remodel-default-theme.css
Code
::
Step2 モーダルを準備する
~~~~~~~~~~~~~~~~~~~~~~~~
| 以下は公式のサンプルに微妙に手を加えたもの。
| ボタンの間の隙間とボタン下のスペースを追加した。
| 本当は公式に乗っているCSSのためのクラスを上書きするべき。
::
Remodal
Responsive, lightweight, fast, synchronized with CSS animations,
fully customizable modal window plugin with
declarative configuration and hash tracking.
Step3 モーダルを操作する
~~~~~~~~~~~~~~~~~~~~~~~~
リンクから呼び出す
::
Call the modal with data-remodal-id="modal"
jQueryをつかって操作する
::
var moda = $("#modal1").remodal(); // モーダルオブジェクトをつくる
// 何かをクリックしたときにモーダルを開く
$("#something_to_open_modal").on("click",function(){
modal.open();
});
// 確認ボタンを押したら閉じる
$(document).on('confirmation', '.remodal', function () {
modal.close();
// and do somothing...
});
// キャンセルボタンを押したら閉じる
$(document).on('cancellation', '.remodal', function () {
modal.close();
// and do somothing...
});
見た目を変える
--------------
デフォルトだとちょっと見た目がいまいちだったので以下の変更をしてみる。
- モーダルの外は覆い隠さない
- モーダル背景を半透明にする
style.css ( remodal の css 2つよりも後に読み込む )
::
.remodal-overlay,
.remodal-wrapper {
background-color: rgba(0,0,0,0);
}
.remodal{
color:white;
background-color: rgba(10,50,20,0.8) ;
padding-bottom: 10px; /*ついでにボタンの下もこっちで変える*/
}
感想
----
| UI Bootstrap に慣れていたので違う環境でモーダルを作るのに戸惑った。
| remodal.js は見た目に bootstrap 感あって違和感なく使えた。
| 何よりも実装が直感的で簡単だったのがよかった。