モーダル風ウインドウを実装する際、jQueryプラグインなどを用いれば、簡単にオシャレなデザインを採用することができますが、カスタマイズに手こずることや、「もっとシンプルなのが良いのに!」って思ったことありませんか?
今回はそんな方のために、モーダルの動作部分だけを極力シンプルなカタチでご用意いたしました。是非参考にしてみてください。
※デモは分かりやすいように少し装飾入れてあります
デモ
×
コンテンツ
html
モーダルボタン
×
コンテンツ
css
#modal_btn {
/* 任意で好きなデザインに */
border: 1px solid #428bca;
padding: 8px 10px;
border-radius: 5px;
margin: 0 0 10px;
display: inline-block;
}
#modal {
display: none;
position: fixed;
z-index: 100;
width: 100%;
}
#modal .contents {
background: #fff;
position: fixed;
z-index: 101;
right: 0;
left: 0;
/* ▽任意で好きな数字に▽ */
width: 80%;
height: 250px;
padding: 10px;
margin-top: -125px;
border-radius: 8px;
}
#modal .contents .close_btn {
/* ▽任意で好きなデザインに▽ */
position: absolute;
right: -5px;
top: -53px;
color: #fff;
display: block;
text-align: center;
font-size: 40px;
cursor: pointer;
}
#modal .overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0,0,0,0.75); /* 黒の濃さ */
}
javascript
※jQueryの読み込みが必要
$("#modal_btn,#modal .close_btn,#modal .overlay").on('click', function(){
if($("#modal_btn").is(".active")){
// 非表示
$("#modal_btn").removeClass("active");
$("#modal").hide();
}else{
// 表示
$("#modal_btn").addClass("active");
$("#modal").show();
}
});
jQueryやcssで少しアニメーションを入れるだけでも、リッチさが増しそうですね!あとはコンテンツの中身次第で大きさや記述を変えてみてください。
リバークレインでは、サイト運営デザイナーを募集しています。
