0

I would like to use headroom.js on my site to be able to hide the header as I scroll down and have it reappear as I scroll up. I am using WordPress.

I tried putting the js file in the theme folder and calling it with functions.php, but it didn't seem to work, so instead I am using this plugin: https://twd.wordpress.org/plugins/headroomjs/.

I have the following in the additional CSS:

.headroom {
transition: transform 200ms linear;
}

.headroom--top .x-navbar {
    background-color: transparent;
    border-bottom: none;
    box-shadow: none;
}
.sub-menu ul li{
 color: #ddd !important;
}

.headroom--top .x-navbar a{
  color: #fff !important;
}

.headroom--top .x-navbar .desktop .sub-menu a{
  color: black !important;
}

.headroom--not-top .x-navbar {
    background-color: #fff;
}

.headroom {
  transition: transform 200ms linear;
}

.headroom--pinned {
    transform: translateY(0%);
}

.headroom--unpinned {
  transform: translateY(-100%);
  webkit-transition: all .3s ease-in-out;
  -moz-transition: all .3s ease-in-out;
  -o-transition: all .3s ease-in-out;
  transition: all .3s ease-in-out;
}

.headroom {
  position: fixed;
  z-index: 12;
  right: 0;
  left: 0;
  top: 0;
  webkit-transition: all .3s ease-in-out;
  -moz-transition: all .3s ease-in-out;
  -o-transition: all .3s ease-in-out;
  transition: all .3s ease-in-out;
}

.masthead {
height:0px;
}

The header color is changing as I scroll down, but it is still fixed, and does not disappear on scroll down. What am I doing wrong?

Thanks!

KnitBecca
  • 1
  • 1

1 Answers1

0

You either need to apply the classes to your templates or use the plugin.

See documentation to correct your install: http://wicky.nillia.ms/headroom.js/

Specifically add an id or data element to your :

<!-- selects $("[data-headroom]") -->

or

<header id="header">

And enqueue the js to functions php, it should call itself; if not, you need to add its document call in the footer template of your theme.

The WordPress plugin hasn't been updated in 3 years so I don't recommend it but you could give it a look and compare it with your install to fix it..

Nathaniel Flick
  • 2,902
  • 2
  • 22
  • 31
  • Thanks I still don't understand how to install it to wordpress correctly - whether in the header or functions or some other way. I did apply the classes to the header, but don't know where to put the js. – KnitBecca Apr 26 '17 at 02:02
  • Sorry, you need to enqueue your script in functions php so WordPress knows about it: https://developer.wordpress.org/themes/basics/including-css-javascript/. I'll add this to my answer. – Nathaniel Flick Apr 26 '17 at 02:53