I have some div
tags on the page and once they are in a viewport, I want them to animate in a certain way. I already got the 'in viewport' part working with waypoint.js
so now I am stuck with the animation.
Basically, I want to have a grey underline on all h1 tags at all times. Once they are in view, I want a black line to run on top of that grey line from right to left and almost leave the scene afterwards, stopping at about 25% of grey line.
To demonstrate it, I've changed the effect to work on hover
and as you can see, I've got the part when it runs through the grey line, but I'm stuck with the part when it should leave the scene (almost leave the scene - stopping at 25% of grey line):
HTML:
<div class="section-header">
<span>Hello</span>
</div>
CSS:
.section-header {
text-transform: uppercase;
font-weight: 700;
font-size: 2em;
letter-spacing: 5px;
position: relative;
text-align: center;
> span {
display: inline-block;
position: relative;
border-bottom: 1px solid #ccc;
&:before {
content: "";
position: absolute;
width: 0;
height: 1px;
bottom: -1px;
right: 0;
background-color: #000;
visibility: hidden;
-webkit-transition: all 0.9s ease-in-out 0s;
transition: all 0.9s ease-in-out 0s;
}
&:hover {
&:before {
visibility: visible;
width: 100%;
}
}
}
}
http://codepen.io/anon/pen/RWoxBv
Is this possible to do in CSS at all? Or should I use Javascript for it?
To demonstrate the animation further, imagine that this is the black line:
- (starts from right hand side and goes to left)
--
---
----
-----
------
-------
--------
---------
----------
-----------
------------ (point when it covers the grey line and starts to 'leave the scene')
-----------
----------
---------
--------
-------
------
-----
----
--- (stopping there)