<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<style type="text/css">
#test{
position: relative;
top: 0px;
left: 0px;
}
.hl-border-div-radiu-shadow{
border-radius: 10px;
box-shadow:0px 0px 5px black ;
}
.guanbi
{
animation:myfirst 1s;
-webkit-animation:myfirst 1s; /* Safari and Chrome */
}
.kaishi{
animation: startk 1s;
-webkit-animation:startk 1s; /* Safari and Chrome */
}
@keyframes startk
{
from {background:yellow;opacity: 0;width: 0px;height: 0px;top: 400px;left: 200px;}
to {background:red;opacity: 1;width: 400px;height: 800px;top: 0px;left: 0px;}
}
@-webkit-keyframes startk /* Safari and Chrome */
{
from {background:yellow;opacity: 0;width: 0px;height: 0px;top: 400px;left: 200px;}
to {background:red;opacity: 1;width: 400px;height: 800px;top: 0px;left: 0px;}
}
@keyframes myfirst
{
from {background:red;opacity: 1;width: 400px;height: 800px;top: 0px;left: 0px;}
to {background:yellow;opacity: 0;width: 0px;height: 0px;top: 400px;left: 200px;}
}
@-webkit-keyframes myfirst /* Safari and Chrome */
{
from {background:red;opacity: 1;width: 400px;height: 800px;top: 0px;left: 0px;}
to {background:yellow;opacity: 0;width: 0px;height: 0px;top: 400px;left: 200px;}
</style>
<body>
</head>
<body>
<p><b>注意:</b> 该实例在 Internet Explorer 9 及更早 IE 版本是无效的。</p>
<div></div>
<button onclick="guanbi('test')">关闭</button>
<button onclick="kaishi('test')">打开</button>
<div id="test" class="hl-border-div-radiu-shadow" style="background-color: red;width:400px; height:800px;" >
</div>
</body>
<script type="text/javascript">
function guanbi(id){
var ele = document.getElementById(id);
ele.className = ele.className.replace(" kaishi","")+" guanbi";;
ele.addEventListener("animationend", function() {
//当前绑定的元素 动画执行完毕时,便会回调此方法
console.log(ele.className);
if(ele.className.search("guanbi")!=-1){
console.log(ele.className);
ele.style.display = "none";
}
});
}
function kaishi(id){
var ele = document.getElementById(id);
ele.className = ele.className.replace(" guanbi","")+" kaishi";
ele.style.display = "block";
}
</script>
</html>
源码下载div隐藏显示过渡动画
- THE END -
最后修改:2020年6月6日