javascript - Logo at the top of navigation bar hide when scroll down -
i'm using bootstrap v3.3.4 make navigation header...here dom navigation bar:
<nav class="navbar navbar-default navbar-fixed-top"> <div class="container-fluid"> <img id="header-logo" src="/assets/img/dashboard/pencil_demo.png"> <hr id="header-nav"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="/">home</a> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">profile <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="/profile/">my profile</a></li> <li><a href="/billing/">my billing</a></li> <li><a href="/badges/">my badges</a></li> </ul> </li> <li class="dropdown"> <a href="/friends/" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">friends <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="/friends/">my friends</a></li> <li><a href="/friends/browse/">search friends</a></li> <li><a href="#" onclick="sendrequestviamultifriendselector();">invite friends</a></li> </ul> </li> <li><a href="/ask/">ask question</a></li> <li><a href="/review/">my revision</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <li><a href=""><span class="circle-image-user" style="margin-top:-6px;"></span></a></li> <li><a href=""><span class="circle-image-school" style="margin-top:-6px;"></span></a></li> <li><a href="/dashboard/">dashboard</a></li> <li><a href="/logout/">logout</a></li> </ul> </div><!--/.nav-collapse --> </div> </nav>
my current output:
how can hide pencil-company logo when scroll down? let navbar when scroll down:
when go @ top...i want keep logo @ top of navigation bar...
sample of company logo:
$(function() { $(window).scroll(function() { var x = $(window).scrolltop(); if (x >= 42) { $("#header-logo").hide(); } else { $("#header-logo").show(); } }); });
#header-logo { height: 100px; } body { height: 5000px; }
<html> <head> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <nav class="navbar navbar-default navbar-fixed-top"> <div class="container-fluid"> <img id="header-logo" src="http://farm4.static.flickr.com/3254/3322981237_7e723b609e.jpg"> <hr id="header-nav"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="/">home</a> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">profile <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="/profile/">my profile</a> </li> <li><a href="/billing/">my billing</a> </li> <li><a href="/badges/">my badges</a> </li> </ul> </li> <li class="dropdown"> <a href="/friends/" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">friends <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="/friends/">my friends</a> </li> <li><a href="/friends/browse/">search friends</a> </li> <li><a href="#" onclick="sendrequestviamultifriendselector();">invite friends</a> </li> </ul> </li> <li><a href="/ask/">ask question</a> </li> <li><a href="/review/">my revision</a> </li> </ul> <ul class="nav navbar-nav navbar-right"> <li><a href=""><span class="circle-image-user" style="margin-top:-6px;"></span></a> </li> <li><a href=""><span class="circle-image-school" style="margin-top:-6px;"></span></a> </li> <li><a href="/dashboard/">dashboard</a> </li> <li><a href="/logout/">logout</a> </li> </ul> </div> <!--/.nav-collapse --> </div> </nav> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> </body> </html>
Comments
Post a Comment