Tuesday, July 16, 2013

Tutorial On Scroll Header Effects

Do you want to share?

Do you like this story?

DEMO     -     DOWNLOAD

Some inspiration for headers that animate when scrolling the page. 
You’ve surely seen those really cool on scroll effects for headers that have been around lately. One example is the header on the Riot Industries website by Phil Renaud which rotates in 3d on click and enlarges when scrolling down. Similar work has been done by Johnny Simpson where he explores Scroll Activated Fixed Header Animations. We’ve also created a Blueprint for an On-Scroll Animated Header to get you started.

The demo for the effects serves as inspiration only and we’ve used a technique that involves changing the state classes of the header which would of course be customized depending on which effect would like to be used. It’s important to understand that the states depend on each other, i.e. changing from class A to class B does something (using transitions) and going from A to C might not cause the desired effect. So the order matters in this example that tries to show all the effects on one page.
Also note that scrolling super fast might cause a jump from the beforementioned class A to class C which might not always look very fancy.
In the demo we use the fantastic jQuery Waypoints plugin by Caleb Troughton.
The header is composed of various parts for showcasing all the effects. It has a perspective wrapper, a front and a bottom (for the 3d rotation):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<header id="ha-header" class="ha-header ha-header-large">
    <div class="ha-header-perspective">
        <div class="ha-header-front">
            <h1><span>Header Effects</span></h1>
            <nav>
                <a>‹ Previous Demo</a>
                <a>Something</a>
                <a>Anything</a>
                <a>Back to the article</a>
            </nav>
        </div>
        <div class="ha-header-bottom">
            <nav>
                <a>Dalliance</a>
                <a>Inglenook</a>
                <a>Lagniappe</a>
                <a>Mellifluous</a>
                <a>Erstwhile</a>
                <a>Wafture</a>
                <a>Serendipity</a>
                <a>Love</a>
            </nav>
        </div>
    </div>
</header>
We add a special class to the sections which will trigger the class change:
1
2
3
<section class="ha-waypoint" data-animate-down="ha-header-small" data-animate-up="ha-header-large">
    <!-- ... -->
</section>
The data atrributes are used for setting the right classes depending on which direction we are scrolling. In our demo the animate-up data attribute contains the class of the previous animate-down one.
An example for a state class is the following “rotate” one:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.ha-header-rotate {
    height: 220px;
    top: 50px;
    padding-left: 50px;
    padding-right: 50px;
}
.ha-header-rotate .ha-header-front {
    transform: translateY(-100%) rotateX(90deg);
}
.ha-header-rotate .ha-header-bottom {
    top: 50%;
    transition: transform 0.5s;
    transform: rotateX(0deg) translateY(-100%);
}
The state classes are applied to the header element and from there we can define some changes for the children.

With the help of the Waypoints plugin we simply add the respective classes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var $head = $( '#ha-header' );
$( '.ha-waypoint' ).each( function(i) {
    var $el = $( this ),
        animClassDown = $el.data( 'animateDown' ),
        animClassUp = $el.data( 'animateUp' );
    $el.waypoint( function( direction ) {
        if( direction === 'down' && animClassDown ) {
            $head.attr('class', 'ha-header ' + animClassDown);
        }
        else if( direction === 'up' && animClassUp ){
            $head.attr('class', 'ha-header ' + animClassUp);
        }
    }, { offset: '100%' } );
} );
We hope you enjoy the effects and that they give you some inspiration on how to make a fancy animated header.

by: Mary Lou (Manoela Ilic)
source: http://tympanus.net/codrops/2013/07/16/on-scroll-header-effects/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+tympanus+%28Codrops%29




YOU MIGHT ALSO LIKE

0 komentar:

Post a Comment

Advertisements

Advertisements