<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>animation</title>
<style>
.pop-modal.modal-in {
opacity: 1;
-webkit-transition-duration: 400ms;
transition-duration: 400ms;
-webkit-transform: translate3d(0, 0, 0) scale(1);
transform: translate3d(0, 0, 0) scale(1);
}
.pop-modal.modal-out {
opacity: 0;
z-index: 10009;
-webkit-transition-duration: 400ms;
transition-duration: 400ms;
-webkit-transform: translate3d(0, 0, 0) scale(0.815);
transform: translate3d(0, 0, 0) scale(0.815);
}
/*.pop-modal {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 9990;
background-color: rgba(0, 0, 0, 0.8);
webkit-transition: -webkit-transform .3s;
transition: -webkit-transform .3s;
transition: transform .3s;
transition: transform .3s, -webkit-transform .3s;
}*/
.pop__content.modal-in {
transform: translate3d(0px, 0px, 0px);
}
.pop__content {
position: absolute;
left: 0;
right: 0;
bottom: 0;
/*height: 700px;*/
/* top: 15%; */
background-color: #fff;
z-index: 5000;
/*-webkit-transition: all 0.2s cubic-bezier(0, 0, 0.25, 1);
transition: all 0.2s cubic-bezier(0, 0, 0.25, 1);
-webkit-transform: translate3d(0, 100%, 0);*/
-webkit-transition: -webkit-transform .3s;
transition: -webkit-transform .3s;
transition: transform .3s;
transition: transform .3s, -webkit-transform .3s;
-webkit-transform: translate3d(0, 100%, 0);
}
.popup-overlay {
display: none;
z-index: 100;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
/*visibility: hidden;*/
opacity: 0;
-webkit-transition-duration: 200ms;
transition-duration: 200ms;
background: rgba(0, 0, 0, 0.6);
/*width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.4);
visibility: hidden;
opacity: 0;
-webkit-transition-duration: 400ms;
transition-duration: 400ms;*/
}
.popup-overlay_visible {
opacity: 1;
visibility: visible;
}
.tm {
font-size: 60px;
}
.pop-dialog__title {
height: 500px;
}
</style>
</head>
<body>
<button id="tm" class="tm">切换modal显示</button>
<buton id="J_close">关闭modal</buton>
<div id="pop" class="pop-modal">
<div class="popup-overlay" id="J_overlay">
</div>
<div class="pop__content">
<div class="pop-dialog__title">
这是弹出内容
</div>
</div>
</div>
<script src="../jquery.js"></script>
<script src="../adapter.js"></script>
<script>
function getStyle(el, styleProp) {
var value, defaultView = (el.ownerDocument || document).defaultView;
// W3C standard way:
if (defaultView && defaultView.getComputedStyle) {
// sanitize property name to css notation
// (hypen separated words eg. font-Size)
styleProp = styleProp.replace(/([A-Z])/g, '-$1').toLowerCase();
return defaultView.getComputedStyle(el, null).getPropertyValue(styleProp);
} else if (el.currentStyle) { // IE
// sanitize property name to camelCase
styleProp = styleProp.replace(/\-(\w)/g, (str, letter) => {
return letter.toUpperCase();
});
value = el.currentStyle[styleProp];
// convert other units to pixels on IE
if (/^\d+(em|pt|%|ex)?$/i.test(value)) {
return ((value) => {
var oldLeft = el.style.left, oldRsLeft = el.runtimeStyle.left;
el.runtimeStyle.left = el.currentStyle.left;
el.style.left = value || 0;
value = el.style.pixelLeft + 'px';
el.style.left = oldLeft;
el.runtimeStyle.left = oldRsLeft;
return value;
})(value);
}
return value;
}
}
$('#J_close').on('click', function () {
// addClass('modal-out')
$('.pop__content').removeClass('modal-in').transitionEnd(function () {
// $('#pop').hide()
$(this).hide()
$('#J_overlay').removeClass('popup-overlay_visible').hide()
})
})
$('#J_overlay').on('click', function () {
// addClass('modal-out')
$('#J_overlay').removeClass('popup-overlay_visible');
$('.pop__content').removeClass('modal-in').transitionEnd(function () {
$(this).hide()
$('#J_overlay').removeClass('popup-overlay_visible').hide()
})
})
$('#tm').on('click', function () {
$('.pop__content').show();
// 只有这样才可以触发动画效果
getStyle($('#pop')[0], 'transform');
$('#J_overlay').addClass('popup-overlay_visible').show();
$('.pop__content').addClass('modal-in');
})
</script>
</body>
</html>