How to make CSS fade out but the HTML to collapse

MyDaftQuestions

I have an element, which has its css style controlled by javascript, simply by adding/removing classes.

For example, I have a hide class, which I apply to an element when I want it to hide, and when the element is hidden the page restructures as if the content was never there (collapse). This is great.

I now want the item to fade out first, and then collapse but I'm lost.

My effort is

 document.getElementById("clicky").addEventListener("click", changeMe);

function changeMe() {
	var ele = document.getElementById("item");   
    ele.className= "hide";
}
#clicky{cursor:pointer;}

.hide {	
	
    animation: fadeout 1s ;
	-webkit-animation: fadeout 1s ; /* Chrome, Safari, Opera */
	animation-fill-mode: forwards;
	-webkit-animation-fill-mode: forwards; 
	}

/* Chrome, Safari, Opera */
@-webkit-keyframes fadeout {
    from {
	display:block;
	visibility:visible;
    opacity: 1;}
    to {
	display:none;
	visibility:hidden;
    opacity:0;}
	
}

/* Standard syntax */
@keyframes fadeout {
    from {
	display:block;
	visibility:visible;
    opacity: 1;}
    to {
	display:none;
	visibility:hidden;
    opacity:0;}
} 
<a id="clicky">Click me</a>
<br /><br />

<div>I remaine!</div>
<div id="item">I should go bye byes but also collapse so the page can re-organise when I disapear!!!!!</div>
<div>I should stay forever but move physically up the page when the line above disappears!</div>

Jason Yaraghi

I would just animate values of max-height in fadeout, e.g.

@keyframes fadeout {
    from {
        max-height: 999px;
        opacity: 1;
    }
    to {
        max-height: 0;
        opacity:0;
    }
} 

Updated fiddle.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to do fade-in and fade-out with JavaScript and CSS

CSS how to make an element fade in and then fade out?

How to make a label fade in or out in swift

How to make fade in/out effect between concatenate videos using ffmpeg

With SDL 2.0 in C, how do I make a rectangle fade in and out?

Make CSS transition fade out after hovered for long enough

How do I make an image fade out but stay in place on scroll?

How to make ul button text fade in and out when button is clicked?

How do I use fade-in/ease-in-out/or any animation to smooth out the revealing of my HTML, CSS and JS navigation menu?

How do I add fade in fade out to inner HTML?

how to make edges of a line fade out?

How to make this JavaScript function fade in or out?

CSS Onmouseexit Fade out

How to make text fade out

How to make a fade out border for uiview

How to make my OpenGL cube "fade" in and out

How to make W3schools Modal example fade out?

How to make fade in/out only happen once

Removing margin space CSS/HTML after animation fade out

CSS Fade In - Fade Out Animation

How can I make fade out text

How to make a single TextView fade in and out with new text

How to make a simple fade in/out panel with jQuery?

I can make an div fade in onclick, but how do i make it fade out?

How to make border for half-circle fade out?

How to make a created div in Javascript fade in and fade out?

How to make a 50% fade in and a 100% fade out?

How to make text fade in instantly but fade out slowly in HTML/CSS?

How to make the shadow fade in (css stylesheet for html)