-
Notifications
You must be signed in to change notification settings - Fork 0
/
shrinkNavScroll.html
117 lines (111 loc) · 4.17 KB
/
shrinkNavScroll.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shrink Navigation on scroll</title>
<style>
*{
margin: 0;padding: 0;
font-family: poppins;
}
#navbar{
background-color: #f1f1f1;
padding: 90px 10px;
overflow: hidden;
transition: 0.4s;
position: fixed;
width: 100%;
top: 0;
z-index: 99;
}
#navbar a{
float: left;
color: black;
text-decoration: none;
font-size: 18px;
padding: 12px;
text-align: center;
border-radius: 4px;
line-height: 25px;
}
#navbar #logo{
font-size: 36px;
font-weight: bold;
transition: 0.4s;
font-family: cambria;
}
#navbar a:hover{
background-color: #ddd;
color: black;
}
#navbar a.active{
background-color: dodgerblue;
color: white;
}
.navRight{
float: right;
}
#home,#News,#Contact{
height: 50vh;
}
@media screen and (max-width: 500px){
#navbar{
padding: 20px 10px !important;
}
#navbar a{
float: left;
text-align: left;
}
#logo{
display: block;
font-size: 20px;
}
.navRight{
float: none;
}
.navRight a{
display: block;
width: 100%;
}
}
</style>
</head>
<body>
<div id="navbar">
<a href="#default" id="logo">Company logo</a>
<div class="navRight">
<a href="#" class="active">Home</a>
<a href="#">News</a>
<a href="#">Contact</a>
</div>
</div>
<div class="content">
<div id="home">
<h1>Home</h1>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Exercitationem omnis aliquam quod temporibus quo officiis itaque impedit vitae voluptates recusandae, tempore voluptatem quisquam suscipit distinctio cum? Iusto esse, consequuntur totam dolorum minima et rem quis, temporibus aperiam aliquid incidunt sit ad velit quos at nostrum minus. Eaque maxime facilis recusandae?</p>
</div>
<div id="News">
<h1>News</h1>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Exercitationem omnis aliquam quod temporibus quo officiis itaque impedit vitae voluptates recusandae, tempore voluptatem quisquam suscipit distinctio cum? Iusto esse, consequuntur totam dolorum minima et rem quis, temporibus aperiam aliquid incidunt sit ad velit quos at nostrum minus. Eaque maxime facilis recusandae?</p>
</div>
<div id="Contact">
<h1>Contact</h1>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Exercitationem omnis aliquam quod temporibus quo officiis itaque impedit vitae voluptates recusandae, tempore voluptatem quisquam suscipit distinctio cum? Iusto esse, consequuntur totam dolorum minima et rem quis, temporibus aperiam aliquid incidunt sit ad velit quos at nostrum minus. Eaque maxime facilis recusandae?</p>
</div>
</div>
<script>
window.onscroll = function() {scrollfunction()};
function scrollfunction(){
if(document.body.scrollTop>80 || document.documentElement.scrollTop>80){
document.getElementById("navbar").style.padding= "30px 10px";
document.getElementById("logo").style.fontSize = "25px";
}else{
document.getElementById("navbar").style.padding= "80px 10px";
document.getElementById("logo").style.fontSize = "35px";
}
}
</script>
</body>
</html>