[英]How to make a bootstrap modal fade in from the bottom?
How do you make a modal fade in from the bottom to the top?你如何使模态从底部到顶部淡入?
By default it starts at the top of the page.默认情况下,它从页面顶部开始。 I want to get it down in the footer.我想把它放在页脚中。
Is there a class of its own for this?有它自己的类吗? I modify the CSS?我修改CSS?
How to do this?这该怎么做?
<div class="modal fade bs-example-modal-lg" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"> ABOUT </h4>
</div>
<div class="modal-body">
CONTEÚDO
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
By default, here is the styling that is used to make the modal fade in from the top:默认情况下,这是用于使模态从顶部淡入的样式:
.modal.fade .modal-dialog {
transform: translate3d(0, -25%, 0);
}
.modal.in .modal-dialog {
transform: translate3d(0, 0, 0);
}
If you want it to fade in from the bottom, change the -25%
value to something like 100vh
or 100%
:如果您希望它从底部淡入,请将-25%
值更改为100vh
或100%
类的值:
.modal.fade .modal-dialog {
transform: translate3d(0, 100vh, 0);
}
.modal.in .modal-dialog {
transform: translate3d(0, 0, 0);
}
Could not find an answer anywhere, so after 5 hours of finding I found out that initially we need to set the height to 0% and when we show the modal we need to set the actual height of the modal and same we need to do at the time of closing this modal.在任何地方都找不到答案,所以经过 5 个小时的查找,我发现最初我们需要将高度设置为 0%,当我们显示模态时,我们需要设置模态的实际高度,同样我们需要在关闭此模态的时间。 For eg - In my case I have given the name of the modal as modal-add-popup
and here is the CSS for making it happen例如 - 在我的例子中,我将模态的名称命名为modal-add-popup
,这是实现它的 CSS
Setting the initial height to 0将初始高度设置为 0
.modal-add-popup {
height: 0;
}
Setting the height to 75% when modal comes up出现模态时将高度设置为 75%
.modal.fade.show .modal-add-popup {
height: 75.5%;
transition: height 0.3s;
}
Setting the height to 0% when modal close down模态关闭时将高度设置为 0%
.modal.fade .modal-add-popup {
height: 0px;
transition: height 0.3s !important;
transition: -webkit-transform 0.3s ease-out;
transition: transform 0.3s ease-out;
transition: transform 0.3s ease-out, -webkit-transform 0.3s ease-out;
-webkit-transform: none;
transform: none;
}
A general approach towards this problem:
Initially the modal will not be in view:
'.modal.fade' is the selector (.fade is bootstrap class) which you can use to give your style.
.modal.fade .modal-dialog {
transform: translate3d(0, 100vh, 0);
}
//By using 100vh we position it below the screen.
When the modal is shown(comes into view) .in and .show are two news classes that get added to .modal element当模态显示(进入视图)时,.in 和 .show 是两个添加到 .modal 元素的新闻类
//By making the earlier 100vh to 0 we position it on the screen at top=0.
//Bootstrap 3
.modal.in .modal-dialog {
transform: translate3d(0, 0, 0);
}
//Bootstrap 4
.modal.show .modal-dialog {
transform: translate3d(0, 0, 0);
}
//Note: To delay the transition you can add rule
transition: transform 0.5s ease-out;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.