Labels

php (35) javascript (31) phpjavascript (30) jquery (23) html (20) mysql (14) database (9) codeigniter (4) json (4) bar chart (2) calendar (2) column chart (2) framework (2) google maps (2) query (2) tables (2) url (2) dropdown (1)

Sunday, July 8, 2018

Hide navbar when user starts to scroll the page down using javascript

Hide a navbar when the user starts to scroll the page using javascript

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
background-color: orange;
font-family: Arial, Helvetica, sans-serif;
}
#navbar {
background-color: #333;
position: fixed;
top: 0;
width: 100%;
display:block;
transition: top 0.3s;
}
#navbar a {
float: left;
display: block;
color: red;
text-align: center;
padding: 15px;
text-decoration: none;
font-size: 17px;
}
#navbar a:hover {
background-color: green;
color: orange;
}
</style>
</head>
<body>
<div id="navbar">
<a href="#home">Home</a>
<a href="#news">News</a>
<a href="#news">About Us</a>
<a href="#news">Contact Us</a>
<a href="#news">Sitemap</a>
</div>
<div style="padding:15px 15px 2500px;font-size:30px;margin-top:30px;">
<p><b>This example demonstrates how to hide a navbar when the user starts to scroll the page.</b></p>
<p>Scroll down this frame to see the effect!</p>
<p>Scroll up to show the navbar.</p>
</div>
<script>
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
document.getElementById("navbar").style.top = "0";
} else {
document.getElementById("navbar").style.top = "-50px";
}
prevScrollpos = currentScrollPos;
}
</script>
</body>
</html>

Result:



10 comments:

  1. Supertech E Square is a great mix of commercial, retail and entertainment offering well place by Supertech Limited at Sector 96, Noida.

    ReplyDelete
  2. ‘Sodom’ in the Garden City: Coded Port Harcourt hangout where rich, horny women hire men for s3x discovered
    ‘Sodom’ in the Garden City: Coded Port Harcourt hangout where rich, horny women hire men for s3x discovered

    A coded joint in Port Harcourt, the Rivers state capital where men and women go to hire men to give them good quality s3x has been discovered.

    The name Port Harcourt represents many things to diverse individuals.


    Read More @ Horny Women hire men for s3x discovered

    ReplyDelete
  3. As students’ college loan debt grows, How much student loan debt is too much?

    With more students attending college, and taking on debt to do it, the nation’s outstanding student loan debt grew by 2.1 percent, to $1.41 trillion, from $1.38 trillion at year-end 2017, according to the Federal Reserve Bank of New York.
    Loans can have some unexpected benefits Read More @

    How much student loan debt is too much?

    ReplyDelete
  4. Your attention to detailed information puts you at the top.
    You are an inspiration to us.
    Web Designing company in kolkata
    psd template/game download/blogs

    ReplyDelete
  5. Hi, So much Thanks for the share. It was very helpful to us. Very informative post.

    ReplyDelete
  6. I Am So Happy To Read This. This Is The Kind Of Manual That Needs To Be Given And Not The Random Misinformation That's At The Other Blogs.

    ReplyDelete
  7. Nice post.
    If you are roadrunner email user and want your Roadrunner Email Password Reset then call roadrunner email helpline +1-888-338-6033.

    ReplyDelete
  8. A debt of gratitude is in order for composing a brilliant article and I got extremely intriguing by understanding It has the most enlightening well ordered directions I have read.If you have any inquiry with Norton then you call our number+18555583999.

    ReplyDelete
  9. pls i want to learn php, jave scrip, and bootstrap factworld.com.ng

    ReplyDelete

More Posts

FOLLOW