Added js for navbar scroll

This commit is contained in:
James Dinh 2022-05-29 16:50:10 -07:00
parent 5fe32ff2c2
commit 34fd5607db
6 changed files with 143 additions and 22 deletions

View File

@ -14,7 +14,6 @@ html {
} }
nav { nav {
/*background: rgb(31, 33, 35);*/
height: auto; height: auto;
width: 100%; width: 100%;
overflow: hidden; overflow: hidden;
@ -23,12 +22,11 @@ nav {
position: fixed; position: fixed;
flex-wrap: nowrap; flex-wrap: nowrap;
z-index: 100; z-index: 100;
/*box-shadow: 0 1px 6px 0 rgb(0 0 0 / 20%);*/
} }
nav * { nav * {
padding: 0; padding: 0;
margin: 1px 1px; margin: 2px 5px;
list-style: none; list-style: none;
box-sizing: border-box; box-sizing: border-box;
z-index: 100; z-index: 100;
@ -110,11 +108,79 @@ nav li a:focus::after{
font-size: 17px; font-size: 17px;
} }
.header-background { #header-background {
background-image: none; background-image: none;
background-position: center; background-position: center;
background-size: cover; background-size: cover;
background-repeat: no-repeat; background-repeat: no-repeat;
background-attachment: fixed; background-attachment: fixed;
height: 100vh; /* makes it so it covers the entire page */ height: 100vh; /* makes it so it covers the entire page */
}
#header {
width: 100%;
height: 100%;
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
background-image: linear-gradient(#0d111733 50%, #0d11175e 60%, #0d1117 100%);
}
#header-subtitle-date {
padding: 5px;
}
#header-subtitle-spots {
padding: 5px;
}
#entrance-arrow {
max-height: 90px;
max-width: 35px;
height: 50px;
position: absolute;
bottom: 10px;
float: bottom;
animation: bounce 3s infinite;
}
@keyframes bounce {
0%, 20%, 50%, 80%, 100% {
transform: translateY(0);
}
40% {
transform: translateY(-5px);
}
60% {
transform: translateY(-3px);
}
}
main {
width: 100%;
padding: 10px 0 10px 0;
align-items: center;
justify-content: center;
text-align: center;
position: relative;
margin: auto;
display: grid;
padding-bottom: 30px;
}
section {
width: auto;
padding: 70px 0px 0 0px;
text-align: center;
align-items: center;
max-width: 1500px;
}
.line {
width: 200px;
margin-bottom: 5px;
} }

5
css/scroll_nav.css Normal file
View File

@ -0,0 +1,5 @@
.pa-fixed-header {
background-color: rgb(24, 24, 24) !important;
box-shadow: 0 1px 6px 0 rgb(0 0 0 / 20%);
transition: background-color 0.25s ease-out;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -12,12 +12,13 @@
<title>Gilroy Hacks</title> <title>Gilroy Hacks</title>
<link href="css/general.css" rel="stylesheet" type="text/css" media="all"> <link href="css/general.css" rel="stylesheet" type="text/css" media="all">
<link href="css/scroll_nav.css" rel="stylesheet" type="text/css" media="all">
<link rel="icon" href=""> <link rel="icon" href="">
<meta name="author" content="Gilroy Hacks"> <meta name="author" content="Gilroy Hacks">
<meta name="copyright" content="This site and its pages are Copyright (c) 2022 Gilroy Hacks All Rights Reserved."> <meta name="copyright" content="This site and its pages are Copyright (c) 2022 Gilroy Hacks All Rights Reserved.">
<meta name="description" content="The official webiste for the Gilroy Hacks Hackathon. Strengthen your skills and collaborate with others to create something useful."> <meta name="description" content="The official webiste for the Gilroy Hacks Hackathon. Strengthen your skills and collaborate with others to create something useful.">
<meta name="keywords" content="Gilroy Hacks, GilroyHacks, Gilroy, hackathon, Bay Area, GECA, Dr. TJ Owens Gilroy Early College Academy"> <meta name="keywords" content="Gilroy Hacks, GilroyHacks, Gilroy, hackathon, Bay Area, GECA, Dr. TJ Owens Gilroy Early College Academy">
<style> <style>
@font-face { @font-face {
font-family: "Glacial Indifference"; font-family: "Glacial Indifference";
@ -34,29 +35,48 @@
</style> </style>
<!--For icons, go here: https://iconsvg.xyz/ --> <!--For icons, go here: https://iconsvg.xyz/ -->
</head> </head>
<body></body>
<!--Nav-->
<nav id="navBar">
<a href="./">
<img src="img/Gilroy Hacks Logo [Summer-wide].png" loading="lazy" height="55" width="auto" alt="logo"/>
</a>
<input type="checkbox" id="check">
<label for="check" class="checkbtn">
<img src="img/bars.png" loading="lazy" height="20" width="25" alt="Bars"/>
</label>
<ul>
<li><a href="event">Event</a></li>
<li><a href="rules">Rules</a></li>
<li><a href="prizes">Prizes</a></li>
<li><a href="teams">Teams</a></li>
<a href=""></a><li id="sign-up">SIGN UP</li></a>
</ul>
</nav>
<!--Front Page-->
<header> <header>
<div class="header-background"> <div id="header-background">
<div id="header"> <div id="header">
<nav> <img id="logo" src="img/Gilroy Hacks Logo [Summer].png" height="300" width="300" loading="lazy" alt="logo"/>
<a href="./"> <hr class="line">
<img id="logo" src="img/Gilroy Hacks Logo [wide transparent].png" loading="lazy" height="55" width="auto" alt="logo"/> <h2 id="header-subtitle-date">Aug 12 - 14</h2>
<h2 id="header-subtitle-spots">40 spots Left</h2>
<div id="entrance-arrow">
<a href="#event" class="link">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9l6 6 6-6"/></svg>
</a> </a>
<input type="checkbox" id="check"> </div>
<label for="check" class="checkbtn">
<img src="img/bars.png" loading="lazy" height="20" width="25" alt="Bars"/>
</label>
<ul>
<li><a href="">Event</a></li>
<li><a href="">Rules</a></li>
<li><a href="">Prizes</a></li>
<li><a href="">Teams</a></li>
<a href=""></a><li id="sign-up">SIGN UP</li></a>
</ul>
</nav>
</div> </div>
</div> </div>
</header> </header>
<body> <!--Main-->
<main>
<section id="event">Event</section>
<section id="rules">Rules</section>
<section id="prizes">Prizes</section>
<section id="teams">Teams</section>
</main>
<script src="js/scroll_nav.js"></script>
</body> </body>
</html> </html>

30
js/scroll_nav.js Normal file
View File

@ -0,0 +1,30 @@
// Toggle the .pa-fixed-header class when the user
// scroll 100px
window.onscroll = () => {scrollNavbar()};
scrollNavbar = () => {
// Target elements
const navBar = document.getElementById("navBar");
const links = document.querySelectorAll("#navBar a");
if (document.documentElement.scrollTop > 100) {
navBar.classList.add("pa-fixed-header");
// Change the color of links on scroll
for (let i = 0; i < links.length; i++) {
const element = links[i];
element.classList.add('text-black');
}
} else {
navBar.classList.remove("pa-fixed-header");
// Change the color of links back to default
for (let i = 0; i < links.length; i++) {
const element = links[i];
element.classList.remove('text-black');
}
}
}