<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
<title></title>
<style>
* {
margin: 0;
padding: 0;
}
.gradient-wrapper {
width: 100%;
display: inline-block;
background-color: red;
height: 200px;
position: absolute;
bottom: 0;
}
.show-animate {
animation: wrapper-gradient .25s linear;
}
@keyframes wrapper-gradient {
0% {
transform: translateY(100%);
}
100% {
transform: translateY(0);
}
}
.hide-animate {
animation: hide-gradient .25s linear;
animation-fill-mode : forwards; // 动画停留在最后一刻,也就是隐藏
}
@keyframes hide-gradient {
0% {
transform: translateY(0);
}
100% {
transform: translateY(100%);
}
}
</style>
</head>
<body>
<div class="gradient-wrapper"></div>
<div class="test">显示隐藏</div>
<script src="js/jquery-1.12.4.min.js" type="text/javascript" charset="utf-8"></script>
<script>
$(function() {
$('.test').on('click', function() {
if ($('.gradient-wrapper').hasClass('show-animate')) {
$('.gradient-wrapper').removeClass('show-animate').addClass('hide-animate');
} else {
$('.gradient-wrapper').removeClass('hide-animate').addClass('show-animate');
}
})
});
</script>
</body>
</html>
|