2
Follows code below. Basically I wanted the div.div2
had a smoother 'climb':
<!DOCTYPE html>
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body{
margin: 0; padding: 0;
}
div{
width: 90%;
height: 50px;
background-color: red;
margin: 20px auto;
}
.div1{
animation: anim 2s forwards;
animation-delay: 2s;
}
.div2{
}
@keyframes anim{
0%{
transform: translateX(0%);
}
100%{
transform: translateX(-200%);
display: none;
}
}
</style>
</head>
<body>
<div class="div1">
</div>
<div class="div2">
</div>
</body>
<script>
$(document).ready(function(){
setTimeout( function () {
$('.div1').remove();
}, 3000);
});
</script>
</html>
This type of transition is usually done by transitioning the
height
of the element up to0px
and then removing the element.– fernandosavio
Fernando I understand, but the top div can not be transitioned this way because it has data that should be displayed...
– Everton Freitas
If the
height
The removal of the element will not be smooth. But note that I have not said that the element needs to be visible. You can, for example, transition theopacity
of1
until0
, and only after that toheight
. That way the content will not be "flattened" in the animation.– fernandosavio