display none animation css code example
Example 1: display transition css
div {
background-color: blue;
padding: 40px;
color: white;
cursor: pointer;
transition: all .1s ease;
}
.hidden {
visibility: hidden;
opacity: 0;
max-height: 0%;
}
.hidden:hover {
visibility: visible;
opacity: 1;
max-height: 1000px;
}
<div class="hidden"></div>
Example 2: css display none transition
div {
border: 1px solid #eee;
}
div > ul {
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.5s linear;
}
div:hover > ul {
visibility: visible;
opacity: 1;
}
Example 3: how to animate div display
<!-- Here's a way to animate/transition
the opacity and display of your div! -->
<style>
@keyframes fadeIn {
0% {display:none; opacity:0;}
1% {display:block; opacity:0;}
100% {display:block; opacity:1;}
}
@keyframes fadeOut {
0% {display:block; opacity:1;}
1% {display:none; opacity:1;}
100% {display: none; opacity:0;}
}
#animate {
animation-duration: 2s;
animation-iteration-count: 1;
display: none;
opacity: 0;
}
</style>
<script>
function appear() {
document.getElementById('animate').style.animationName = "example";
}
</script>
<!-- You can put anything to activate the function, by the way. -->
<button onclick="appear()"> example </button>
<!-- This div is what's being animated, which explains why the function
appear() has 'animate' in it. -->
<div id="animate"> </div>