如何使用css或js在关闭时将Bootstrap 4模式对话框向右滑动

How do slide bootstrap 4 modal dialog to right when closing using css or js(如何使用css或js在关闭时将Bootstrap 4模式对话框向右滑动)
本文介绍了如何使用css或js在关闭时将Bootstrap 4模式对话框向右滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个引导模式,当打开时,我应用css动画从右侧滑入,它工作得很好,但我希望在单击自定义关闭按钮时将其滑回右侧,而不是在没有动画的情况下只是隐藏。

请任何人知道我如何做到这一点,我已经在网上搜索过,但我看到的只是如何在打开时应用动画。 数据-lang="js"数据-隐藏="假"数据-控制台="真"数据-巴贝尔="假">

function customOpen(element){
  $(element).modal({
    backdrop: false,
    keyboard: false
  });
}
function customClose(element){
  $(element).modal('hide');
}
$(document).on("click", "#open", function() {
  var elem = $(this).attr("data-element");
  customOpen(elem);
});
$(document).on("click", "#close", function() {
  var elem = $(this).attr("data-element");
  customClose(elem);
});
.modal.fade {
    transition: opacity .0s linear !important;
}
.modal.fade:not(.show).left .modal-dialog {
	-webkit-transform: translate3d(-125%, 0, 0);
	-ms-transform: translate3d(-125%, 0, 0);
	-o-transform: translate3d(-125%, 0, 0);
	transform: translate3d(-125%, 0, 0);
}
.modal.fade:not(.show).right .modal-dialog {
	-webkit-transform: translate3d(125%, 0, 0);
	-ms-transform: translate3d(125%, 0, 0);
	-o-transform: translate3d(125%, 0, 0);
	transform: translate3d(125%, 0, 0);
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

<div class="modal modal-full fade right" id="newPage">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
        <p>One fine body&hellip;</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" id="close" data-element='#newPage'>Close</button>
      </div>
    </div>
  </div>
</div>

<a class='btn btn-primary btn' id="open" data-element='#newPage'>Open Right</a>

推荐答案

只需使用一个自定义类modal-right,并相应地更改modal-dialogtransform属性。默认情况下,引导从top应用。

数据-lang="js"数据-隐藏="假"数据-控制台="真"数据-巴贝尔="假">
.modal.fade.modal-right .modal-dialog {
  transform: translate(125%, 0px);
}

.modal.show.modal-right .modal-dialog {
  transform: none;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

<div class="modal fade modal-right" id="newPage" tabindex="-1" role="dialog" aria-labelledby="newPage" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
        <p>One fine body&hellip;</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">Close</button>
      </div>
    </div>
  </div>
</div>

<a class="btn btn-primary" data-toggle="modal" data-target="#newPage">Open Right</a>

这篇关于如何使用css或js在关闭时将Bootstrap 4模式对话框向右滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)