This is probably something really, really stupid that I have missed but my CSS animations aren't working as expected. Instead of the elements fading out and in respectively, I just get a quick, nasty change between them.
Apologies in advance as my classes may be confusing at first. before
is the class content I want to show BEFORE hover. after
is the class of content which should show AFTER (or during) hover.
There should be a css opacity animation which makes all BEFORE content fade out and all AFTER content fade in but I can't get it to work.
I have referenced the following sites and SO articles before posting:
- Bavotasan: A simple fade with CSS 3
- SO: Using CSS for fade-in effect on page load
- SO: Show button on hover only
CSS (SCSS):
.homepage-services-hover {
position: relative;
display: inline-block;
vertical-align: top;
width: 100%;
height: auto;
.before {
position: relative;
top: 0;
left: 0;
visibility: visible;
opacity: 1;
}
.after {
position: absolute;
top: 0;
left: 0;
visibility: visible;
opacity: 0;
}
&:hover {
.before {
opacity: 0;
transition: opacity .5s;
-moz-transition: opacity .5s;
-webkit-transition: opacity .5s;
position: absolute;
top: 0;
left: 0;
visibility: visible;
}
.after {
opacity: 1;
transition: opacity .5s;
-moz-transition: opacity .5s;
-webkit-transition: opacity .5s;
position: relative;
top: 0;
left: 0;
visibility: visible;
}
}
}
HTML:
<span class="homepage-services-hover" style="width: 175px; text-align: center;">
<a href="#">
<img class="before" src="https://placehold.it/150x150" alt="IMAGE" />
<span class="before">
<h5>Title</h5>
<P>
Excerpt
</P>
</span>
</a>
<img class="after" src="https://placehold.it/175x175" alt="IMAGE"/>
<a class="button after" href="#">TITLE</a>
</span>
All the dev is done on a local server so I can't post a live link.
I weren't aware that JSFiddle supported SASS so here is a Fiddle.