cssで下から出てくるモーダルの動きを作ってます。
同じクラス名で複数設置可能です。
動作サンプル
See the Pen 下からスライドして出てくる感じのモーダル by takapen (@takapen) on CodePen.
html
btnコンテンツ
close
btn2コンテンツ2
close
css
/*モーダル用*/ .js-modal__bg { width: 100%; height: 100%; background-color: rgba(0,0,0,0.6); position: fixed; top: 0; left: 0; z-index: 10; display: none; } .js-modal__main { width: calc(100% - 32px); height: 80%; padding: 16px; bottom: -81%; left: 0; background: #fff; border-radius:4px 4px 0 0 ; position: fixed; z-index: 11; opacity: 0; } .js-modal__btn { color:#76952f; cursor: pointer; -webkit-tap-highlight-color:rgba(0,0,0,0); } .js-modal__btn--close { margin-top: 40px; text-align: center; text-decoration: underline; } .js-modal__btn--close--fix { width: 30px; height: 30px; //background: #333; border-radius: 50%; position: absolute; top: -50px; right: 5px; z-index: 101; cursor:pointer; -webkit-tap-highlight-color:rgba(0,0,0,0); } .js-modal__btn--close--fix:before{ content:""; width: 20px; height: 20px; border-right:3px solid #fff; transform: rotate(-45deg); position: absolute; top:12px; left:-3px; } .js-modal__btn--close--fix:after{ content:""; width: 20px; height: 20px; border-right:3px solid #fff; transform: rotate(45deg); position: absolute; top:-2px; left:-3px; } /*下から上*/ @keyframes SlideUp { 0% { opacity: 0; transform: translateY(-1%); } 100% { opacity: 1; transform: translateY(-80%); } } /*上から下*/ @keyframes SlideDown { 0% { opacity: 1; transform: translateY(-80%); } 100% { opacity: 0; transform: translateY(-1%); } } .js-modal__main._slideUp { animation: SlideUp .5s ease-in-out forwards; } .js-modal__main._slideDown { animation: SlideDown .5s ease-in-out forwards; }
jquery
$(function(){ var modalBtn = $('.js-modal__btn'); var modalBtnClose = $('.js-modal__btn--close'); var modalBtnCloseFix = $('.js-modal__btn--close--fix'); var modalBg = $('.js-modal__bg'); var modalMain = $('.js-modal__main'); modalBtn.on('click', function (e) { $(this).next(modalBg).fadeIn(); $(this).next(modalBg).next(modalMain).removeClass("_slideDown"); $(this).next(modalBg).next(modalMain).addClass("_slideUp"); }); modalBtnClose.on('click', function (e) { modalBg.fadeOut(); modalMain.removeClass("_slideUp"); modalMain.addClass("_slideDown"); }); modalBtnCloseFix.on('click', function (e) { modalBg.fadeOut(); modalMain.removeClass("_slideUp"); modalMain.addClass("_slideDown"); }); modalMain.on('click', function (e) { e.stopPropagation(); }); modalBg.on('click', function () { $(this).fadeOut(); $(this).next(modalMain).removeClass("_slideUp"); $(this).next(modalMain).addClass("_slideDown"); }); });