cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <link href='https://fonts.googleapis.com/css?family=Oswald:400,300,700' rel='stylesheet' type='text/css'>

<!-- [data-animate-header-container] - this is the header container used for calculating when the header is in/out of view -->
<header class='header' data-animate-header-container>

	<!-- [data-animate-header] - this is the actual element that will be fixed/animated -->
	<menu class='header-bar' data-animate-header>
		<a href='#menu' class='btn-menu' data-toggle-class='menu-active'>Menu</a>
		<a href='#menu' class='btn-search' data-toggle-class='search-active'>Search</a>
	</menu>
</header>

<article class='article'>
	<header class='article-header'>
		<h1 class='article-title'>Animate header in &amp; out</h1>
		<span class='article-subtitle'>When white section hits top of screen.</span>
	</header>

	<!-- [data-animate-header-target] - this is where the header will animate -->
	<section class='article-section' data-animate-header-target>
		<p>Using jquery-waypoints, well be checking to see when [data-animate-header] (this section) is above the top of screen, then animate [data-animate-header] (the fixed header) in/out accordingly.  We're able to do this with css transitions and a combo of 3 classes (.header-past, .header-show, .header-hide) - without having to clone or do any dom manipulating.</p>
	</section>
</article>
            
          
!
            
              // Demo Reusables
$cubic-bezier: cubic-bezier(0.215, 0.61, 0.355, 1);
$font: 'Oswald', sans-serif;
$header-height: 40px;

// Calc
@mixin calc($property, $value) {
	#{$property}: -webkit-calc(#{$value});
	#{$property}:    -moz-calc(#{$value});
	#{$property}:         calc(#{$value});
}

// Fonts
%font-bold {
	font-weight: 700;
}

%font-light {
	font-weight: 300;
	letter-spacing: .15em;
}

%font-regular {
	font-family: $font;
	font-weight: 400;
}

// Crispy/Better Font Rendering
%text-crispy {
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

// Demo Styles
* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

body {
	@extend %font-regular;
	// @extend %text-crispy;
	background-color: #F4F4F4;
	color: #2b2b2b;
	font-size: 14px;
	letter-spacing: .1em;
	text-align: center;
}

body, html, article {
	height: 100%;
}

// Page Header
.article-header {
	background-color: #E31E25;
	color: white;
	display: flex;
	flex-flow: column;
	height: 80%;
	justify-content: center;
	line-height: 1.3;
	min-height: 200px;
	padding: 2em 4% 2em;
	@include calc('padding-top', '2em + #{$header-height}');
}

.article-section {
	line-height: 200%;
	margin: 0 auto;
	max-width: 680px;
	padding: 3em 2em 100vh;
	text-align: justify;
}

.article-subtitle {
	@extend %font-light;
	font-style: italic;
	display: block;
}

.article-title {
	@extend %font-light;
	font-size: 1.8rem;
	margin-bottom: 10px;
	text-transform: uppercase;
}

.header-bar {
	display: flex;
	font-size: 12px;
	justify-content: space-between;
	text-transform: uppercase;

	a {
		color: white;
		text-decoration: none;
	}
}

// Fixed Header (Layout Stuff & Animations)
// [data-animate-header]
[data-animate-header] { // use class selector in production
	background-color: #1b1b1b;
	left: 0;
	padding: 12px 10px 11px; // 40px
	position: absolute;
	right: 0;
	top: 0;
	z-index: 1;

	// Hide the header offscreen so we can transition it in later
	.header-past & {
		position: fixed;
		top: -$header-height;
	}

	// Hide the header (slideUp)
	.header-past.header-hide & {
		top: -$header-height;
		transition: top .85s $cubic-bezier;
	}

	// Show the header (slideDown)
	.header-show & {
		top: 0;
		transition: top .85s $cubic-bezier;
	}
}
            
          
!
            
              // External js being loaded - https://cdnjs.cloudflare.com/ajax/libs/waypoints/2.0.5/waypoints.min.js
$(function() {
    waypoints.init();
})

var waypoints = {
    init: function() {
        // container - used for toggling classes to animate content
        this.container = $('html');

        // header - main header container: an inner wrapper element should get fixed (.header-bar)
        this.header = $('[data-animate-header-container]');

        // headerHeight - the inner header element that gets fixed
        this.headerHeight = $('[data-animate-header]').outerHeight();

        // targetElement - when this element hits top of screen the header  animates
        this.targetElement = $('[data-animate-header-target]');

        // bindControls
        this.bindControls();
    },
    animateHeader: function() {
        var self = this;

        // Add class when header is in/out of view
        self.header.waypoint(function(direction) {
            if (direction === "up") {
                self.container.removeClass('header-past header-hide');
            } else {
                self.container.addClass('header-past');
            }
        }, { offset: -self.headerHeight });

        // Animate header in when this element hits top of screen
        self.targetElement.waypoint(function(direction) {
            if (direction === "up") {
                self.container.addClass('header-hide').removeClass('header-show');
            } else {
                self.container.addClass('header-show').removeClass('header-hide');
            }
        }, { offset: 0 });
    },
    bindControls: function () {
        var self = this;

        self.animateHeader();
    },
}
            
          
!
999px
Loading ..................

Console