javascript - Hide fixed header on scroll down, show on scroll up and hover version 2 please -
i know question has been asked here before, don't way scripted , looks unstable when running.
i following:
- hide header on scroll down fadeout
- show header on scroll fadein
- show header on hover
i decided not show of js other examples, because people intend work on those, don't work good.
hope can must easy coder.
html:
<header> <nav> <div class="mob-nav"> <div class="nav-toggle"><i class="nav-icon"></i></div> </div> <ul class="left-nav"> <li class="home"><a href="#">pixelation</a></li> </ul> <ul class="right-nav"> <li><a href="#">work</a></li> <li><a href="#">about</a></li> </ul> </nav> </header>
use scroll function in jquery -
$(document).ready(function(){ var iscrollpos = 0; $(window).scroll(function () { var icurscrollpos = $(this).scrolltop(); if (icurscrollpos > iscrollpos) { $('header').fadeout(500); } else { $('header').fadein(500); } iscrollpos = icurscrollpos; }); }); * { margin: 0; padding: 0; -webkit-box-sizing: border-box; /* width , height value includes content, padding , border not margin */ -moz-box-sizing: border-box; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0,0,0,0); /* remove highlight on touch devices */ -webkit-tap-highlight-color: transparent; } html { position: relative; min-height: 100%; /* sticky footer */ overflow-y: scroll; height: 2500px; } body { font-family: "helvetica neue", helvetica, arial, sans-serif; font-weight: normal; font-size: 18px; line-height: 1.4; letter-spacing: 1px; color: #000; } body, input, textarea, select, button { text-rendering: optimizelegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } header { position: fixed; width: 100%; top: 0; left: 0; margin: 0; padding: 0; z-index: 9999; background-color: #eee; } .mob-nav { display: none; /* hide mobile nav */ } nav ul.left-nav { float: left; } nav ul.right-nav { float: right; } nav { position: relative; padding: 0 5px; } nav ul { list-style: none; font-size: 0; /* remove default spacing */ } nav li { display: inline-block; } nav { display: block; font-size: 18px; font-weight: normal; text-transform: uppercase; text-align: center; text-decoration: none; background-color: transparent; padding: 0 10px; line-height: 44px; } nav a:link, nav a:visited { color: #111; text-decoration: none; } nav a:hover, nav a:active { color: #999; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <header> <nav> <div class="mob-nav"> <div class="nav-toggle"><i class="nav-icon"></i></div> </div> <ul class="left-nav"> <li class="home"><a href="#">pixelation</a></li> </ul> <ul class="right-nav"> <li><a href="#">work</a></li> <li><a href="#">about</a></li> </ul> </nav> </header>
Comments
Post a Comment