Skip to content

Instantly share code, notes, and snippets.

@benknight
Last active August 29, 2015 13:55
Show Gist options
  • Save benknight/8739800 to your computer and use it in GitHub Desktop.
Save benknight/8739800 to your computer and use it in GitHub Desktop.
Yelp Fixed Header v1
(function() {
if ( ! document.body.classList.contains('logged-in') ) {
alert('Please log in before using this bookmarklet. I’m too lazy to make it work for logged-out.');
} else {
var fixAt = 77;
var showAt = 600;
var headerClassList = document.querySelector('.app-header').classList;
window.onscroll = function() {
if ( window.scrollY > fixAt && ! headerClassList.contains('fixed') ) {
headerClassList.add('fixed');
} else if ( window.scrollY <= fixAt && headerClassList.contains('fixed') ) {
headerClassList.remove('fixed', 'slide-in', 'slide-out');
}
if ( window.scrollY > showAt && ! headerClassList.contains('slide-in') ) {
headerClassList.add('slide-in');
headerClassList.remove('slide-out');
} else if ( window.scrollY <= showAt && headerClassList.contains('slide-in') ) {
headerClassList.remove('slide-in');
headerClassList.add('slide-out');
}
};
}
})();
// ----
// Sass (v3.3.0.rc.2)
// Compass (v1.0.0.alpha.17)
// ----
@import "compass/css3/transform";
@import "compass/css3/transition";
// Prevent "jump" in content offset
#wrap {
padding-top: 77px;
}
.app-header {
position: absolute;
top: 0;
width: 100%;
height: 77px;
&.fixed {
position: fixed;
height: 50px;
@include transform(translateY(calc(-100% - 10px)));
&.slide-in,
&.slide-out {
@include transition(transform 0.5s);
}
&.slide-in {
@include transform(translateY(0));
}
.logo {
background-size: 100%;
width: 80px;
height: 40px;
margin: 4px 15px 5px 0;
}
#header-nav {
display: none;
}
.header-search-form {
padding-top: 9px;
}
.header-account {
margin-top: 9px;
}
}
}
// Make location dropdown and autocomplete positioned according to the header again
#dropper,
.autocomplete_choices {
position: fixed !important;
top: 40px !important;
}
#wrap {
padding-top: 77px;
}
.app-header {
position: absolute;
top: 0;
width: 100%;
height: 77px;
}
.app-header.fixed {
position: fixed;
height: 50px;
-moz-transform: translateY(calc(-100% - 10px));
-ms-transform: translateY(calc(-100% - 10px));
-o-transform: translateY(calc(-100% - 10px));
-webkit-transform: translateY(calc(-100% - 10px));
transform: translateY(calc(-100% - 10px));
}
.app-header.fixed.slide-in, .app-header.fixed.slide-out {
-moz-transition: -moz-transform 0.5s;
-o-transition: -o-transform 0.5s;
-webkit-transition: -webkit-transform 0.5s;
transition: transform 0.5s;
}
.app-header.fixed.slide-in {
-moz-transform: translateY(0);
-ms-transform: translateY(0);
-o-transform: translateY(0);
-webkit-transform: translateY(0);
transform: translateY(0);
}
.app-header.fixed .logo {
background-size: 100%;
width: 80px;
height: 40px;
margin: 4px 15px 5px 0;
}
.app-header.fixed #header-nav {
display: none;
}
.app-header.fixed .header-search-form {
padding-top: 9px;
}
.app-header.fixed .header-account {
margin-top: 9px;
}
#dropper,
.autocomplete_choices {
position: fixed !important;
top: 40px !important;
}
<body>
<head>
<meta charset="utf-8">
</head>
Drag me into the bookmarks bar:<br>
<a href="javascript:(function(){var gist_id='8739800';var css=[];var js=[];var applyCSS=function(){for(var x in css){var style=document.createElement('style');style.innerHTML=css[x];document.head.appendChild(style);}};var applyJS=function(){for(var x in js){var script=document.createElement('script');script.innerHTML=js[x];document.body.appendChild(script);}};var xhr=new XMLHttpRequest();xhr.open('GET','https://api.github.com/gists/'+gist_id,true);xhr.onload=function(){var data=JSON.parse(this.responseText);for(var file in data.files){if(data.files[file].language=='CSS'){css.push(data.files[file].content);}if(data.files[file].language=='JavaScript'){js.push(data.files[file].content);}}applyCSS();applyJS();};xhr.onerror=function(){console.log('Failed to load Gist: '+request.gist);};xhr.send();}());">
Fixed header
</a>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment