CSS Animation: Chasing Navigation Idea
So I found this pen I wrote about a month ago. Just wanted to share what I came up with and hopefully provide you with some coding inspiration.
My initial idea was to create a navigation that follows when you scroll without using position: fixed; So I tried to come up with a CSS solution.
Usually you would see something like this:
#header {
position: fixed;
top: 0;
z-index: 1;
// rest of code...
}
That works just fine, however, this becomes a problem on iOS devices. In my experience, there will be a delay and the header will look choppy. There will be times where the header wont follow.
So I started to write some code (which is still a work in progress) that uses CSS transforms to provide a chasing navigation menu.
First I initialized the keyframe property like so:
/**chasing animation*/
@keyframes chase{
from {
-webkit-transform: translateY(0px);
transform: translateY(0px);
}
to {
-webkit-transform: translateY(175px);
transform: translateY(175px);
}
}
For the sake of browser support, you should use vendor prefixes:
@-webkit-keyframes chase {}
@-moz-keyframes chase {}
If you’re SASS or Less user, you could either write a mixin for this or use an auto-prefixer. I can explain these in detail in another article.
Next, we have to call the “animation” property in order for it to work.
#menu {
// code
-webkit-animation: chase 2s ease infinite;
animation: chase 2s ease infinite;
}
Inside the property, you call the chase keyframe that you defined, the delay, easing and duration of the animation.
Here is the full example:
See the Pen Animating Chasing Navigation by Tyler Souza (@tysweezy) on CodePen.
Hopefully that provides some ideas. I plan to use some Javascript/jQuery to detect the scrolling when it gets to a certain height.
Anyway, more to come soon. Stay tuned.