Skip to content

Instantly share code, notes, and snippets.

@vishnusomanus
Last active June 2, 2017 05:17
Show Gist options
  • Save vishnusomanus/0d4bb377447eb943e316b128caf3ec52 to your computer and use it in GitHub Desktop.
Save vishnusomanus/0d4bb377447eb943e316b128caf3ec52 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
@keyframes headerAnimation {
from {top: -80px;}
to {top: 0px;}
}
body.fixed header {
position: fixed;
width: 100%;
background-color: #fff;
animation-name: headerAnimation;
animation-duration: 0.3s;
animation-fill-mode: forwards;
}
body.fixed {
margin-top: 56px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery(window).scroll(function() {
if (jQuery(document).scrollTop() > 75) {
jQuery('body').addClass('fixed');
} else {
jQuery('body').removeClass('fixed');
}
});
});
</script>
<header style="height: 80px; background: #ccc;"></header>
<div style="height: 800px"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment