I have successfully added a CSS animation to my Bootstrap modal that slides in from the right when opening, which looks great. However, I am looking for a way to slide it back to the right when a custom close button is clicked, instead of just hiding it without any animation.
If anyone has an idea on how I can achieve this, please let me know. I have searched online but all I could find was information on applying animations on open only.
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…</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>