LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

Resizing Fixed Header

Scroll down to initiate resizing of the page header.

CSS
body {
  height: 1500px;
  background: url(https://www.brainpickings.org/wp-content/themes/brainpickings/images/bckgd_body.png);
}

.offset {
  margin-top: 0;
  padding-top: 270px;
  text-align: center;
  -webkit-transition: .3s;
  transition: .3s;
}

.header {
  position: fixed;
  width: 100%;
  height: 250px;
  font-weight: bold;
  text-align: center;
  background: gold;
  -webkit-transition: .3s;
  transition: .3s;
}
.header.small {
  height: 70px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}
.header.small ~ .offset {
  padding-top: 140px;
}
.header.small .header_logo {
  padding-top: 20px;
  font-size: 20px;
  text-shadow: none;
}

.header_logo {
  font-family: 'Oswald', sans-serif;
  margin: 0;
  padding-top: 80px;
  font-size: 50px;
  text-shadow: 3px 4px rgba(0, 0, 0, 0.1);
  -webkit-transition: .3s;
  transition: .3s;
}
JS
$(document).scroll(function() {
  navbarScroll();
});

function navbarScroll() {
  var y = window.scrollY;
  if (y > 10) {
    $('.header').addClass('small');
  } else if (y < 10) {
    $('.header').removeClass('small');
  }
}
Host Instantly Drag and Drop Website Builder

 

Description

I was inspired by the header on brainpickings.org. I like the way it uses the full size on page load and almost immediately after the user starts scrolling it shrinks down to a resonable size.
Term
Mon, 11/27/2017 - 21:41

Related Codes

Pen ID
Pen ID
Pen ID