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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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>

<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>

	<!-- [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>
              // 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() {

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
    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 {
        }, { offset: -self.headerHeight });

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


Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.


Loading ..................