I have a one page layout where I need to make my "Contact Us" section highlight active (ie. Highlight the navbar links background blue) as my other links do when clicked and are scrolled to.
I guess the easiest way to do this is make it active when the page is scrolled to the bottom. I've tried adding a few things to my javascript but it hasn't worked.
EDIT:
I'm almost there I have added this bit of code to my jQuery and added two class elements to my HTML a href, but now when I scroll up "Get A Quote" does't highlight/active until I scroll past it then back down. Any suggestions?
Changed HTML
<li class="quoteive">
Get A Quote
</li>
<li class="contactive">
Contact Us
</li>
Added Code
$(window).on("scroll", function() {
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
$(".contactive").addClass('active');
$(".quoteive").removeClass('active');
}
else {
$(".contactive").removeClass('active');
}
});
Here is my ORIGINAL code:
window.onload=function(){
// Cache selectors
var lastId,
topMenu = $("#top-menu"),
topMenuHeight = topMenu.outerHeight()+15,
// All list items
menuItems = topMenu.find("a"),
// Anchors corresponding to menu items
scrollItems = menuItems.map(function(){
var item = $($(this).attr("href"));
if (item.length) { return item; }
});
// Bind click handler to menu items
// so we can get a fancy scroll animation
menuItems.click(function(e){
var href = $(this).attr("href"),
offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1;
$('html, body').stop().animate({
scrollTop: offsetTop
}, 300);
e.preventDefault();
});
// Bind to scroll
$(window).scroll(function(){
// Get container scroll position
var fromTop = $(this).scrollTop()+topMenuHeight;
// Get id of current scroll item
var cur = scrollItems.map(function(){
if ($(this).offset().top < fromTop)
return this;
});
// Get the id of the current element
cur = cur[cur.length-1];
var id = cur && cur.length ? cur[0].id : "";
if (lastId !== id) {
lastId = id;
// Set/remove active class
menuItems
.parent().removeClass("active")
.end().filter("[href='#"+id+"']").parent().addClass("active");
}
});
}//]]>
#font-face {
font-family: 'Montserrat';
src: url('fonts/Montserrat-Regular.otf')
}
#font-face {
font-family: 'MontserratSlim';
src: url('fonts/Montserrat-ExtraLight.otf')
}
body {
font-family: Helvetica, Arial;
margin: 0px;
}
#header {
top: 0px;
}
.signsize {
width: 140px;
height: 90px;
}
.movesimg {
float: right;
}
.packing {
float: left;
}
h1 {
font-family: 'Montserrat';
font-size: 50px;
text-align: right;
color: #3d3d3d;
margin:0;
}
h2 {
margin: 0;
color: #3d3d3d;
}
h3 {
color: #3d3d3d;
}
h4 {
font-family: 'Montserrat';
font-size: 50px;
text-align: left;
color: #3d3d3d;
margin:0;
}
h5 {
font-size: 50px;
padding-top: 60px;
color: #3d3d3d;
margin: 0;
}
h6 {
font-family: 'MontserratSlim';
font-size: 15px;
text-align: left;
color: #929292;
margin:0;
}
#descriptionl {
font-family: 'MontserratSlim';
font-size: 15px;
color: #929292;
margin:0;
}
#descriptionr {
font-family: 'MontserratSlim';
font-size: 15px;
color: #929292;
text-align: right;
margin:0;
}
#movessec {
display: inline-block;
padding-top: 60px;
padding-bottom: 60px;
border-bottom: solid thin #d8d8d8;
}
#navbar {
position: fixed;
z-index: 1;
background: white;
right: 0px;
top: 0px;
width: 100%;
}
#logo {
float: left;
margin-left: 10%;
padding-top: 10px;
padding-bottom: 10px;
}
#top-menu {
z-index: 1;
float: right;
padding-right: 10%;
padding-top: 25px;
padding-bottom: 25px;
}
#top-menu li {
float: left;
list-style-type: none;
white-space: nowrap;
font-size: 15px;
font-family: Montserrat;
text-transform: uppercase;
font-weight: 600;
text-align: center;
letter-spacing: 1px;
}
#more {
padding-left: 50px;
}
#moreR {
padding-right: 50px;
}
#more li {
float: left;
list-style-type: none;
white-space: nowrap;
font-size: 15px;
font-family: Montserrat;
text-transform: uppercase;
font-weight: 600;
text-align: center;
letter-spacing: 1px;
padding: 8px;
outline: #4690d4 solid thin;
text-decoration: none;
}
#moreR li {
float: right;
list-style-type: none;
white-space: nowrap;
font-size: 15px;
font-family: Montserrat;
text-transform: uppercase;
font-weight: 600;
text-align: center;
letter-spacing: 1px;
padding: 8px;
outline: #4690d4 solid thin;
text-decoration: none;
}
#top-menu a {
display: inline;
width: 6em;
text-align: center;
padding: 15px;
-webkit-transition: .5s all ease-out;
-moz-transition: .5s all ease-out;
transition: .5s all ease-out;
color: #545454;
text-decoration: none;
letter-spacing: 1px;
}
#top-menu a:hover {
color: #575757;
}
#top-menu li.active a {
color: white;
position: relative;
background: #4690d4;
}
#home {
padding-left: 70px;
padding-top: 150px;
height: 800px;
background-image: url(img/movingboxes.jpg);
background-size: cover;
background-repeat: no-repeat;
font-family: Montserrat;
}
#services {
height: 1600px;
}
#servicesleft {
float: left;
height: 100%;
width: 12%;
}
#servicesmain {
float: left;
height: 100%;
width: 76%;
}
#servicesright {
float: left;
height: 100%;
width: 12%;
}
#moving {
height: 800px;
padding-top: 50px;
padding-left: 12%;
padding-right: 12%;
background-image: url('img/cardboardbright.jpg');
font-family: Montserrat;
}
#quote {
height: 800px;
background: grey;
}
#contact {
height: 325px;
}
#contactleft {
float: left;
height: 100%;
width: 12%;
background: white;
}
#contactmain {
float: left;
height: 100%;
width: 76%;
background: white;
}
#contactright {
float: left;
height: 100%;
width: 12%;
background: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div id="header">
<div id="navbar">
<div id="logo">
<img src="logosmall.png">
</div>
<ul id="top-menu">
<li class="active">
Home
</li>
<li>
Services
</li>
<li>
Moving Tips
</li>
<li>
Get A Quote
</li>
<li>
Contact Us
</li>
</ul>
</div>
</div>
<div id="home">
Content Here.
</div>
<div id="services">
<div id="servicesleft"></div>
<div id="servicesmain">
<div id="movessec">
Content Here.
</div>
<div id="movessec">
Content Here.
</div>
<div id="movessec">
Content Here.
</div>
</div>
<div id="servicesright"></div>
</div>
<div id="moving">Content here.</div>
<div id="quote">Quote form goes here.</div>
<div id="contact">
<div id="contactleft">Content Here</div>
<div id="contactmain">Content Here</div>
<div id="contactright">Content Here</div>
</div>
</body>
There is simple css solution via Relative position with negative top and padding fixing.
#contact {
z-index: -1;
position: relative;
top: -200px;
padding-top: 200px;
}
Now #contact container start earlier and the content showing in the same position.
Note: you can change the px number and get your own result, and don't forget to lower the z-index container.
Example:
window.onload=function(){
// Cache selectors
var lastId,
topMenu = $("#top-menu"),
topMenuHeight = topMenu.outerHeight()+15,
// All list items
menuItems = topMenu.find("a"),
// Anchors corresponding to menu items
scrollItems = menuItems.map(function(){
var item = $($(this).attr("href"));
if (item.length) { return item; }
});
// Bind click handler to menu items
// so we can get a fancy scroll animation
menuItems.click(function(e){
var href = $(this).attr("href"),
offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1;
$('html, body').stop().animate({
scrollTop: offsetTop
}, 300);
e.preventDefault();
});
// Bind to scroll
$(window).scroll(function(){
// Get container scroll position
var fromTop = $(this).scrollTop()+topMenuHeight;
// Get id of current scroll item
var cur = scrollItems.map(function(){
if ($(this).offset().top < fromTop)
return this;
});
// Get the id of the current element
cur = cur[cur.length-1];
var id = cur && cur.length ? cur[0].id : "";
if (lastId !== id) {
lastId = id;
// Set/remove active class
menuItems
.parent().removeClass("active")
.end().filter("[href='#"+id+"']").parent().addClass("active");
}
});
}//]]>
#font-face {
font-family: 'Montserrat';
src: url('fonts/Montserrat-Regular.otf')
}
#font-face {
font-family: 'MontserratSlim';
src: url('fonts/Montserrat-ExtraLight.otf')
}
body {
font-family: Helvetica, Arial;
margin: 0px;
}
#header {
top: 0px;
}
.signsize {
width: 140px;
height: 90px;
}
.movesimg {
float: right;
}
.packing {
float: left;
}
h1 {
font-family: 'Montserrat';
font-size: 50px;
text-align: right;
color: #3d3d3d;
margin:0;
}
h2 {
margin: 0;
color: #3d3d3d;
}
h3 {
color: #3d3d3d;
}
h4 {
font-family: 'Montserrat';
font-size: 50px;
text-align: left;
color: #3d3d3d;
margin:0;
}
h5 {
font-size: 50px;
padding-top: 60px;
color: #3d3d3d;
margin: 0;
}
h6 {
font-family: 'MontserratSlim';
font-size: 15px;
text-align: left;
color: #929292;
margin:0;
}
#descriptionl {
font-family: 'MontserratSlim';
font-size: 15px;
color: #929292;
margin:0;
}
#descriptionr {
font-family: 'MontserratSlim';
font-size: 15px;
color: #929292;
text-align: right;
margin:0;
}
#movessec {
display: inline-block;
padding-top: 60px;
padding-bottom: 60px;
border-bottom: solid thin #d8d8d8;
}
#navbar {
position: fixed;
z-index: 1;
background: white;
right: 0px;
top: 0px;
width: 100%;
}
#logo {
float: left;
margin-left: 10%;
padding-top: 10px;
padding-bottom: 10px;
}
#top-menu {
z-index: 1;
float: right;
padding-right: 10%;
padding-top: 25px;
padding-bottom: 25px;
}
#top-menu li {
float: left;
list-style-type: none;
white-space: nowrap;
font-size: 15px;
font-family: Montserrat;
text-transform: uppercase;
font-weight: 600;
text-align: center;
letter-spacing: 1px;
}
#more {
padding-left: 50px;
}
#moreR {
padding-right: 50px;
}
#more li {
float: left;
list-style-type: none;
white-space: nowrap;
font-size: 15px;
font-family: Montserrat;
text-transform: uppercase;
font-weight: 600;
text-align: center;
letter-spacing: 1px;
padding: 8px;
outline: #4690d4 solid thin;
text-decoration: none;
}
#moreR li {
float: right;
list-style-type: none;
white-space: nowrap;
font-size: 15px;
font-family: Montserrat;
text-transform: uppercase;
font-weight: 600;
text-align: center;
letter-spacing: 1px;
padding: 8px;
outline: #4690d4 solid thin;
text-decoration: none;
}
#top-menu a {
display: inline;
width: 6em;
text-align: center;
padding: 15px;
-webkit-transition: .5s all ease-out;
-moz-transition: .5s all ease-out;
transition: .5s all ease-out;
color: #545454;
text-decoration: none;
letter-spacing: 1px;
}
#top-menu a:hover {
color: #575757;
}
#top-menu li.active a {
color: white;
position: relative;
background: #4690d4;
}
#home {
padding-left: 70px;
padding-top: 150px;
height: 800px;
background-image: url(img/movingboxes.jpg);
background-size: cover;
background-repeat: no-repeat;
font-family: Montserrat;
}
#services {
height: 1600px;
}
#servicesleft {
float: left;
height: 100%;
width: 12%;
}
#servicesmain {
float: left;
height: 100%;
width: 76%;
}
#servicesright {
float: left;
height: 100%;
width: 12%;
}
#moving {
height: 800px;
padding-top: 50px;
padding-left: 12%;
padding-right: 12%;
background-image: url('img/cardboardbright.jpg');
font-family: Montserrat;
}
#quote {
height: 800px;
background: grey;
}
#contact {
z-index: -1;
height: 325px;
position: relative;
top: -200px;
padding-top: 200px;
}
#contactleft {
float: left;
height: 100%;
width: 12%;
background: white;
}
#contactmain {
float: left;
height: 100%;
width: 76%;
background: white;
}
#contactright {
float: left;
height: 100%;
width: 12%;
background: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div id="header">
<div id="navbar">
<div id="logo">
<img src="logosmall.png">
</div>
<ul id="top-menu">
<li class="active">
Home
</li>
<li>
Services
</li>
<li>
Moving Tips
</li>
<li>
Get A Quote
</li>
<li>
Contact Us
</li>
</ul>
</div>
</div>
<div id="home">
Content Here.
</div>
<div id="services">
<div id="servicesleft"></div>
<div id="servicesmain">
<div id="movessec">
Content Here.
</div>
<div id="movessec">
Content Here.
</div>
<div id="movessec">
Content Here.
</div>
</div>
<div id="servicesright"></div>
</div>
<div id="moving">Content here.</div>
<div id="quote">Quote form goes here.</div>
<div id="contact">
<div id="contactleft">Content Here</div>
<div id="contactmain">Content Here</div>
<div id="contactright">Content Here</div>
</div>
</body>
EDIT:
Check this js, I think its goes well.
$(window).scroll(function(){
var scrollPosition = $(window).scrollTop();
//get the page height
var pageHeight = $('body').outerHeight();
//get the window height
var windowHeight = $(window).innerHeight();
$('.quoteive').each(function(){
var parent = $(this).parent(),
target = $(this).children('a').attr('href'),
targetPosition = $(target).offset().top - 100,
targetHeight = $(target).outerHeight();
if (scrollPosition > targetPosition && scrollPosition < targetPosition + targetHeight) {
$(this).addClass('active');
} else if (pageHeight - windowHeight <= scrollPosition) {
$(parent).children().removeClass('active');
$(parent).children().last().addClass('active');
} else {
$(this).removeClass('active');
}
})
})
And this is your HTML code:
<ul id="top-menu">
<li class="quoteive">
Home
</li>
<li class="quoteive">
Services
</li>
<li class="quoteive">
Moving Tips
</li>
<li class="quoteive">
Get A Quote
</li>
<li class="quoteive">
Contact Us
</li>
</ul>
If you what to get the switch before the bottom of the page just change this line:
else if (pageHeight - windowHeight <= scrollPosition)
to this line (you can write your choice):
else if (pageHeight - windowHeight <= scrollPosition + 100)
Working fiddle
Related
I'm a beginner trying to code a navbar in a practice website but I can't get the final product right.
My navbar is supposed to line up horizontally along the top of the page and then be follow the page as you scroll with a black shadow backdrop. Currently when you load the page, the words line up vertically on the right side, and then condense when you scroll. I also have a logo in the top left that shrinks way too small. Finally, when when you shrink the page, a hamburger icon pops up in the top right that is supposed to show you the menu options, however it no longer works. It's like a cycle with this page, I fix one thing and break another. I am doing this just for fun because I'm trying to learn but now I'm getting frustrated, Thanks!
$(window).on('scroll', function() {
if ($(window).scrollTop()) {
$('nav').addClass('black');
} else {
$('nav').removeClass('black');
}
})
$(document).ready(function() {
$(".menu i").click(function() {
$("nav ul").toggleClass("active")
})
})
#import url('https://fonts.googleapis.com/css?family=Bungee|Bungee+Hairline|Oswald|Raleway&display=swap');
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
nav {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100px;
padding: 10px 100px;
box-sizing: border-box;
transition: .5s;
}
nav.black {
background: rgba(0, 0, 0, .8);
height: 80px;
padding: 10px 50px;
}
nav.logo {
float: left;
}
nav .logo img {
height: 80px;
transition: .5s;
}
nav.black .logo img {
padding: 20px;
height: 60px;
}
nav ul {
float: right;
margin: 0;
padding: 0px;
display: flex;
text-shadow: 2px 2px 4px #000000;
}
nav ul li {
List-style: none;
}
nav ul li a {
Line-height: 80px;
color: #fff;
padding: 5px 20px;
font-family: 'Raleway', sans-serif;
text-decoration: none;
text-transform: uppercase;
transition: .5s;
}
nav.black ul li a {
color: #fff;
Line-height: 20px;
}
nav ul li a.active,
nav ul li a:hover {
color: #fff;
background: #008cff;
}
.responsive-bar {
display: none;
}
#media (max-width: 800px) {
.responsive-bar {
display: block;
width: 100%;
height: 60px;
background: #262626;
position: fixed;
top: 0;
Left: 0;
padding: 5px 20px;
box-sizing: border-box;
z-index: 1;
}
.responsive-bar .logo img {
float: left;
height: 50px;
}
.responsive-bar .menu i {
float: right;
color: #fff;
margin: 0;
padding: 0;
Line-height: 50px;
cursor: pointer;
text-transform: uppercase;
}
nav {
padding: 60px;
}
nav.black {
display: none;
background: #262626;
height: 60px;
padding: 0;
}
nav .logo {
display: none;
}
nav ul {
position: absolute;
width: 100%;
top: 60;
Left: 0;
background: #262626;
float: none;
display: none;
}
nav ul.active {
display: block;
}
nav ul li {
width: 100%
}
nav ul li a {
display: block;
padding: 15px;
width: 100%;
height: 60px;
text-align: center;
Line-height: 30px;
color: #fff;
}
}
* {
box-sizing: border-box;
}
.main {
height: 1000px;
padding-left: 20px;
padding-right: 100px;
}
<div class="responsive-bar">
<div class="logo">
<img src="img/logo.png">
</div>
<div class="menu">
<i class="fa fa-bars"></i>
</div>
</div>
<nav>
<div class="logo">
<img src="img/logo.png">
</div>
<ul>
<div class="active">
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Portfolio</li>
<li>Contact</li>
</div>
</ul>
</nav>
<div class="main">
</div>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
I want to create a 'scroll-nav' for my website. So I separated 2 Navs and added some jquery:
<nav class="main-nav clearfix">
<?php wp_nav_menu(array('theme_location' => 'main_nav')); ?>
</nav>
<nav id="scroll-nav" style="display:none">
<?php wp_nav_menu(array('theme_location' => 'main_nav')); ?>
</nav>
$(window).scroll(function() {
if ($(window).scrollTop() > 50 ){
$('#scroll-nav').css('display', 'block');
} else {
$('#scroll-nav').css('display', 'none');
};
});
But it´s not working. Do I have to do something different because of WordPress? It tested it in a normal html, it works fine there.
You are putting clearfix like ID when you have to do it in class attribute.
<nav id="scroll-nav" class="clearfix" style="display:none">
And put your
$(window).scroll(function() {
if ($(window).scrollTop() > 50 ){
$('#scroll-nav').css('display', 'block');
} else {
$('#scroll-nav').css('display', 'none');
};
});
into
$(document).ready(function(){
});
#import url(http://fonts.googleapis.com/css?family=Pacifico|Roboto:400,500);
nav {
background: #333;
overflow: auto;
padding: 60px;
position: relative;
z-index: 2;
}
ul {
text-align: center;
float: right;
}
ul li {
display: inline-block;
}
ul li a {
text-decoration: none;
display: block;
padding: 5px 10px;
margin: 0 10px;
color: #eee;
font-family: 'Roboto', sans-serif;
text-transform: uppercase;
font-size: 14px;
line-height: 32px;
font-weight: bold;
transition: all 200ms linear;
}
nav a:hover,
nav#small a:hover {
color: #C18055;
background: #fff;
}
nav#small {
background: #fff;
padding: 20px 40px;
position: fixed;
box-sizing: border-box;
width: 100%;
top: 0;
z-index: 1;
box-shadow: 0px 2px 2px #fff;
}
nav#small h1,
nav#small a {
color: #333;
}
nav#small h1 {
font-size: 38px;
}
nav#small h1>a {
color: #C18055;
}
nav#small h1>a:hover {
color: #3ab4a6;
}
div#content {
height: 2200px;
background: url('https://s-media-cache-ak0.pinimg.com/originals/03/95/6f/03956fed74537b3d7b0858e9a814748d.jpg')repeat 0 0;
opacity: 0.9;
}
div#content h2 {
color: #fff;
font-weight: bold;
transform: rotate(-10deg);
line-height: 60px;
font-size: 48px;
text-transform: uppercase;
position: fixed;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
position: absolute;
width: 10%;
bottom: 10%;
text-shadow: 2px 2px 2px #333;
font-family: 'Pacifico', cursive;
}
div#content h2:before {
display: inline-block;
background: url('http://www.menoftheras.com/wp-content/gallery/test/arrow.png')no-repeat 0 0;
background-size: cover;
width: 239px;
height: 200px;
content: "";
transform: rotate(-80deg);
margin-bottom: 40px;
}
#media (max-width: 700px) {
nav {
padding: 20px;
}
nav h1 {
display: block;
float: none;
text-align: center;
padding: 20px;
}
nav ul {
float: none;
padding: 20px;
}
div#content h2 {
width: 30%;
}
nav#small {
padding: 20px;
}
nav#small ul {
padding: 5px;
}
nav#small h1 {
padding: 10px;
font-size: 28px;
margin-bottom: 5px;
}
nav#small a {
font-weight: normal;
}
}
<header>
<nav>
<ul>
<li>Home</li>
<li>Gallery</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
<nav id="small">
<ul>
<li>Home</li>
<li>Gallery</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
</header>
<div id="content">
<h2>Scroll!</h2>
</div>
Would you please check my above snippet?
I created a slideToggle menu that for some reason seems to jump around when it slides up and down. The border bottom of the sliding header just flies around and glitches when the menu slides up and down, but otherwise the slideToggle works fine.
I've tried setting the position of the .headermenu to relative as well as hiding the overflow, but neither of these seemed to have fixed the issue. Does slide toggle just not work properly with a border bottom or is the issue in my code?
The glitch is difficult to explain, but the glitch shows in my code snippet, so I suggest you view it to get an understanding of what's happening. Basically the border bottom is bouncing around when the menu slides down.
In order to activate the drop down header you have to click the little broken image in the corner, which will activate the menu (so you can see the glitch in action.)
Is it related to some sort of start height for the animation? Do I need the animation to start at a specific point in the page or is it something else entirely?
$(document).ready(function(){
$("button").click(function(){
$(".headermenu").slideToggle();
$(".headermenu").height('150')
});
});
* {
box-sizing: border-box;
}
#font-face {
font-family: 'monaco';
src: url('monaco-webfont.woff2') format('woff2'),
url('monaco-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
a {
font-family: 'monaco';
font-size: 16px;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:visited {
color: blue;
}
body {
margin: 0px;
}
button {
background: none;
border: none;
float: right;
margin-right: 40px;
margin-top: 15px;
padding: 0px;
}
#hamburger {
padding-top: 2px;
width: 27px;
}
header {
background-color: blue;
border-bottom: solid white 1px;
color: white;
float: left;
height: 60px;
padding-top: 4px;
position: fixed;
width: 100%;
z-index: 150px;
}
.headermenu {
background-color: blue;
border-bottom: solid white 1px;
color: white;
display: none;
font-family: 'monaco';
height: 200px;
overflow: hidden;
padding-top: 40px;
position: relative;
width: 100%;
/*-webkit-transition: all .5s;
transition: all .5s;
height: 0;*/
}
.headermenu a {
color: white;
float: right;
padding-right: 40px;
text-decoration: none;
}
.headermenu a:hover {
text-decoration: underline;
}
.headermenu a:visited {
color: white;
}
#headermenuleft {
float: right;
line-height: 25px;
text-align: left;
}
#headermenuleft ul {
list-style-type: none;
}
#headermenuright {
float: right;
line-height: 25px;
text-align: left;
}
#headermenuright ul {
list-style-type: none;
}
<!DOCTYPE HTML>
<html>
<head>
<link href="css/main.css" rel="stylesheet"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="js/main.js"></script>
<title>Why Have There Been No Great Women Artists?</title>
</head>
<body>
<header>
<button><img id="hamburger" src="images/Menu,_Web_Fundamentals_(White).svg.png"></button>
<a id="home" href="index.html">Why Have There Been No Great Women Artists?</a>
<div class="headermenu">
<div id="headermenuleft">
<ul>
<li>Georgia O'Keeffe</li>
<li>Frida Kahlo</li>
<li>Artemisia Gentileschi</li>
</ul>
</div>
<div id="headermenuright">
<ul>
<li>The Essay</li>
<li>Judy Chicago</li>
<li>Kara Walker</li>
<li>Ana Mendieta</li>
</ul>
</div>
</div>
</header>
</body>
</html>
$(document).ready(function () {
$("button").click(function () {
$(".headermenu").slideToggle('slow', function () {
$(this).height('150');
});
});
});
* {
box-sizing: border-box;
}
#font-face {
font-family: 'monaco';
src: url('monaco-webfont.woff2') format('woff2'),
url('monaco-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
a {
font-family: 'monaco';
font-size: 16px;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:visited {
color: blue;
}
body {
margin: 0px;
}
button {
background: none;
border: none;
float: right;
margin-right: 40px;
margin-top: 15px;
padding: 0px;
}
#essay {
background-color: white;
height: 400px;
padding-top: 60px;
width: 100%;
}
#essaytext {
width: 830px;
margin: auto;
padding-top: 30px;
}
#gallery {
background-color: blue;
height: 1000px;
width: 100%;
}
#gallery a{
color: white;
}
#gallery h2 {
color: white;
font-size: 28px;
}
#gallerytext {
margin: auto;
padding-bottom: 50px;
padding-top: 50px;
width: 830px;
}
#grid {
margin: auto;
padding-top: 30px;
width: 830px;
}
#gridone {
background-color: white;
color: blue;
display: block;
float: left;
height: 200px;
padding-top: 20px;
padding-left: 25px;
width: 400px;
}
#gridtwo {
background-color: white;
color: blue;
display: block;
float: right;
height: 200px;
padding-top: 20px;
padding-left: 25px;
width: 400px;
}
#gridthree {
background-color: white;
color: blue;
display: block;
float: left;
height: 200px;
margin-top: 30px;
padding-top: 20px;
padding-left: 25px;
width: 400px;
}
#gridfour {
background-color: white;
color: blue;
display: block;
float: right;
height: 200px;
margin-top: 30px;
padding-top: 20px;
padding-left: 25px;
width: 400px;
}
#gridfive {
background-color: white;
color: blue;
display: block;
float: right;
height: 200px;
margin-top: 30px;
padding-top: 20px;
padding-left: 25px;
width: 400px;
}
#gridsix {
background-color: white;
color: blue;
display: block;
float: left;
height: 200px;
margin-top: 30px;
padding-top: 20px;
padding-left: 25px;
width: 400px;
}
#hamburger {
padding-top: 2px;
width: 27px;
}
header {
background-color: blue;
border-bottom: solid white 1px;
color: white;
float: left;
padding-top: 4px;
position: fixed;
width: 100%;
z-index: 150;
}
header > div:first-child
{
height: 60px;
}
.headermenu {
background-color: blue;
border-bottom: solid white 1px;
color: white;
display: none;
font-family: 'monaco';
height: 200px;
overflow: hidden;
padding-top: 40px;
position: relative;
width: 100%;
/*-webkit-transition: all .5s;
transition: all .5s;
height: 0;*/
}
.headermenu a {
color: white;
float: right;
padding-right: 40px;
text-decoration: none;
}
.headermenu a:hover {
text-decoration: underline;
}
.headermenu a:visited {
color: white;
}
#headermenuleft {
float: right;
line-height: 25px;
text-align: left;
}
#headermenuleft ul {
list-style-type: none;
}
#headermenuright {
float: right;
line-height: 25px;
text-align: left;
}
#headermenuright ul {
list-style-type: none;
}
#home {
color: white;
display: block;
font-family: 'monaco';
font-size: 16px;
padding-left: 40px;
padding-right: 0px;
padding-top: 17px;
margin: auto;
}
h2 {
color: blue;
font-family: 'monaco';
font-size: 28px;
font-weight: normal;
}
nav#mobile-nav {
display: none;
z-index: 100;
width: 100%;
}
p {
font-family: 'monaco';
font-size: 16px;
line-height: 21px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<div>
<button><img id="hamburger" src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Menu,_Web_Fundamentals.svg/2000px-Menu,_Web_Fundamentals.svg.png"></button>
<a id="home" href="index.html">Why Have There Been No Great Women Artists?</a>
</div>
<div class="headermenu">
<div id="headermenuleft">
<ul>
<li>Georgia O'Keeffe</li>
<li>Frida Kahlo</li>
<li>Artemisia Gentileschi</li>
</ul>
</div>
<div id="headermenuright">
<ul>
<li>The Essay</li>
<li>Judy Chicago</li>
<li>Kara Walker</li>
<li>Ana Mendieta</li>
</ul>
</div>
</div>
</header>
<div id="essay">
<div id="essaytext">
<h2>The Essay</h2>
<p>“Why Have There Been No Great Women Artists?” is an essay by Linda Nochlin that details how centuries of oppression and misogyny has led to a male dominated art world. Nochlin explains through her essay how sexism has prevented women from fully being recognized as historically significant artists.</p>
Read The Essay →
</div>
</div>
<div id="gallery">
<div id="gallerytext">
<h2>The Gallery</h2>
<p>This website is intended to shed a light on the many incredible women in art who have been overshadowed due to their gender. By viewing the gallery you can see the incredible works of women artists whose significant contributions to the art world have been cast aside because of their womanhood.</p>
<div id="grid">
<a href="./judy.html">
<div id="gridone">
"The Dinner Party"<br>
Judy Chicago
</div>
</a>
<a href="./kara.html">
<div id="gridtwo">
"A Subtlety"<br>
Kara Walker
</div>
</a>
<a href="./mendieta.html">
<div id="gridthree">
"Alma Silueta en Fuego"<br>
Ana Mendieta
</div>
</a>
<a href="./georgia.html">
<div id="gridfour">
"Black Iris"<br>
Georgia O'Keeffe
</div>
</a>
<a href="./frida.html">
<div id="gridfive">
"The Two Fridas"<br>
Frida Kahlo
</div>
</a>
<a href="./artemesia.html">
<div id="gridsix">
"Judith Slaying Holofernes"<br>
Artemisia Gentileschi
</div>
</a>
</div>
</div>
</div>
The problem is you have a white bottom border in .headermenu. If you remove that that fixes the problem.
There are other issues however, you are using pixels in the z-index, when that parameter only accepts a number.
Also, it doesn't look to me like you need $(".headermenu").height('150');. If you do, then it should be $(".headermenu").height(150); - without the quote around the number of pixels.
EDIT
It appears you need to add top: 6px; to .headermenu (at least to look correct to me in Firefox). I can't tell you why exactly, but it appears to be to do with the hamburger button being floated and not taking up enough vertical height (padding/margin).
$(document).ready(function(){
$("button").click(function(){
$(".headermenu").slideToggle();
});
});
* {
box-sizing: border-box;
}
#font-face {
font-family: 'monaco';
src: url('monaco-webfont.woff2') format('woff2'),
url('monaco-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
a {
font-family: 'monaco';
font-size: 16px;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:visited {
color: blue;
}
body {
margin: 0px;
}
button {
background: none;
border: none;
float: right;
margin-right: 40px;
margin-top: 15px;
padding: 0px;
}
#essay {
background-color: white;
height: 400px;
padding-top: 60px;
width: 100%;
}
#essaytext {
width: 830px;
margin: auto;
padding-top: 30px;
}
#gallery {
background-color: blue;
height: 1000px;
width: 100%;
}
#gallery a{
color: white;
}
#gallery h2 {
color: white;
font-size: 28px;
}
#gallerytext {
margin: auto;
padding-bottom: 50px;
padding-top: 50px;
width: 830px;
}
#grid {
margin: auto;
padding-top: 30px;
width: 830px;
}
#gridone {
background-color: white;
color: blue;
display: block;
float: left;
height: 200px;
padding-top: 20px;
padding-left: 25px;
width: 400px;
}
#gridtwo {
background-color: white;
color: blue;
display: block;
float: right;
height: 200px;
padding-top: 20px;
padding-left: 25px;
width: 400px;
}
#gridthree {
background-color: white;
color: blue;
display: block;
float: left;
height: 200px;
margin-top: 30px;
padding-top: 20px;
padding-left: 25px;
width: 400px;
}
#gridfour {
background-color: white;
color: blue;
display: block;
float: right;
height: 200px;
margin-top: 30px;
padding-top: 20px;
padding-left: 25px;
width: 400px;
}
#gridfive {
background-color: white;
color: blue;
display: block;
float: right;
height: 200px;
margin-top: 30px;
padding-top: 20px;
padding-left: 25px;
width: 400px;
}
#gridsix {
background-color: white;
color: blue;
display: block;
float: left;
height: 200px;
margin-top: 30px;
padding-top: 20px;
padding-left: 25px;
width: 400px;
}
#hamburger {
padding-top: 2px;
width: 27px;
}
header {
background-color: blue;
border-bottom: solid red 1px;
color: white;
float: left;
height: 60px;
padding-top: 4px;
position: fixed;
width: 100%;
z-index: 150;
}
.headermenu {
background-color: green;
border-bottom: solid red 1px;
color: white;
display: none;
font-family: 'monaco';
height: 200px;
overflow: hidden;
padding-top: 60px;
position: relative;
width: 100%;
top: 6px;
/*-webkit-transition: all .5s;
transition: all .5s;
height: 0;*/
z-index: 200;
}
.headermenu a {
color: white;
float: right;
padding-right: 40px;
text-decoration: none;
}
.headermenu a:hover {
text-decoration: underline;
}
.headermenu a:visited {
color: white;
}
#headermenuleft {
float: right;
line-height: 25px;
text-align: left;
}
#headermenuleft ul {
list-style-type: none;
}
#headermenuright {
float: right;
line-height: 25px;
text-align: left;
}
#headermenuright ul {
list-style-type: none;
}
#home {
color: white;
display: block;
font-family: 'monaco';
font-size: 16px;
padding-left: 40px;
padding-right: 0px;
padding-top: 17px;
margin: auto;
}
h2 {
color: blue;
font-family: 'monaco';
font-size: 28px;
font-weight: normal;
}
nav#mobile-nav {
display: none;
z-index: 100;
width: 100%;
}
p {
font-family: 'monaco';
font-size: 16px;
line-height: 21px;
}
<!DOCTYPE HTML>
<html>
<head>
<link href="css/main.css" rel="stylesheet"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="js/main.js"></script>
<title>Why Have There Been No Great Women Artists?</title>
</head>
<body>
<header>
<button><img id="hamburger" src="images/Menu,_Web_Fundamentals_(White).svg.png"></button>
<a id="home" href="index.html">Why Have There Been No Great Women Artists?</a>
<div class="headermenu">
<div id="headermenuleft">
<ul>
<li>Georgia O'Keeffe</li>
<li>Frida Kahlo</li>
<li>Artemisia Gentileschi</li>
</ul>
</div>
<div id="headermenuright">
<ul>
<li>The Essay</li>
<li>Judy Chicago</li>
<li>Kara Walker</li>
<li>Ana Mendieta</li>
</ul>
</div>
</div>
</header>
</body>
</html>
My one page layout is working perfectly except for one issue. The navbar links when clicked changes color according to where the user goes to or scrolls.
The problem is that when I click on the "Contact Us" link, the navbar scrolls to that position but the navbar link doesn't change color as pictured above. It works for every other section just not for the bottom because the area isn't big enough.
window.onload=function(){
// Cache selectors
var lastId,
topMenu = $("#top-menu"),
topMenuHeight = topMenu.outerHeight()+15,
// All list items
menuItems = topMenu.find("a"),
// Anchors corresponding to menu items
scrollItems = menuItems.map(function(){
var item = $($(this).attr("href"));
if (item.length) { return item; }
});
// Bind click handler to menu items
// so we can get a fancy scroll animation
menuItems.click(function(e){
var href = $(this).attr("href"),
offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1;
$('html, body').stop().animate({
scrollTop: offsetTop
}, 300);
e.preventDefault();
});
// Bind to scroll
$(window).scroll(function(){
// Get container scroll position
var fromTop = $(this).scrollTop()+topMenuHeight;
// Get id of current scroll item
var cur = scrollItems.map(function(){
if ($(this).offset().top < fromTop)
return this;
});
// Get the id of the current element
cur = cur[cur.length-1];
var id = cur && cur.length ? cur[0].id : "";
if (lastId !== id) {
lastId = id;
// Set/remove active class
menuItems
.parent().removeClass("active")
.end().filter("[href='#"+id+"']").parent().addClass("active");
}
});
}//]]>
#font-face {
font-family: 'Montserrat';
src: url('fonts/Montserrat-Regular.otf')
}
#font-face {
font-family: 'MontserratSlim';
src: url('fonts/Montserrat-ExtraLight.otf')
}
body {
font-family: Helvetica, Arial;
margin: 0px;
}
#header {
top: 0px;
}
.signsize {
width: 140px;
height: 90px;
}
.movesimg {
float: right;
}
.packing {
float: left;
}
h1 {
font-family: 'Montserrat';
font-size: 50px;
text-align: right;
color: #3d3d3d;
margin:0;
}
h2 {
margin: 0;
color: #3d3d3d;
}
h3 {
color: #3d3d3d;
}
h4 {
font-family: 'Montserrat';
font-size: 50px;
text-align: left;
color: #3d3d3d;
margin:0;
}
h5 {
font-size: 50px;
padding-top: 60px;
color: #3d3d3d;
margin: 0;
}
h6 {
font-family: 'MontserratSlim';
font-size: 15px;
text-align: left;
color: #929292;
margin:0;
}
#descriptionl {
font-family: 'MontserratSlim';
font-size: 15px;
color: #929292;
margin:0;
}
#descriptionr {
font-family: 'MontserratSlim';
font-size: 15px;
color: #929292;
text-align: right;
margin:0;
}
#movessec {
display: inline-block;
padding-top: 60px;
padding-bottom: 60px;
border-bottom: solid thin #d8d8d8;
}
#navbar {
position: fixed;
z-index: 1;
background: white;
right: 0px;
top: 0px;
width: 100%;
}
#logo {
float: left;
margin-left: 10%;
padding-top: 10px;
padding-bottom: 10px;
}
#top-menu {
z-index: 1;
float: right;
padding-right: 10%;
padding-top: 25px;
padding-bottom: 25px;
}
#top-menu li {
float: left;
list-style-type: none;
white-space: nowrap;
font-size: 15px;
font-family: Montserrat;
text-transform: uppercase;
font-weight: 600;
text-align: center;
letter-spacing: 1px;
}
#more {
padding-left: 50px;
}
#moreR {
padding-right: 50px;
}
#more li {
float: left;
list-style-type: none;
white-space: nowrap;
font-size: 15px;
font-family: Montserrat;
text-transform: uppercase;
font-weight: 600;
text-align: center;
letter-spacing: 1px;
padding: 8px;
outline: #4690d4 solid thin;
text-decoration: none;
}
#moreR li {
float: right;
list-style-type: none;
white-space: nowrap;
font-size: 15px;
font-family: Montserrat;
text-transform: uppercase;
font-weight: 600;
text-align: center;
letter-spacing: 1px;
padding: 8px;
outline: #4690d4 solid thin;
text-decoration: none;
}
#top-menu a {
display: inline;
width: 6em;
text-align: center;
padding: 15px;
-webkit-transition: .5s all ease-out;
-moz-transition: .5s all ease-out;
transition: .5s all ease-out;
color: #545454;
text-decoration: none;
letter-spacing: 1px;
}
#top-menu a:hover {
color: #575757;
}
#top-menu li.active a {
color: white;
position: relative;
background: #4690d4;
}
#home {
padding-left: 70px;
padding-top: 150px;
height: 800px;
background-image: url(img/movingboxes.jpg);
background-size: cover;
background-repeat: no-repeat;
font-family: Montserrat;
}
#services {
height: 1600px;
}
#servicesleft {
float: left;
height: 100%;
width: 12%;
}
#servicesmain {
float: left;
height: 100%;
width: 76%;
}
#servicesright {
float: left;
height: 100%;
width: 12%;
}
#moving {
height: 800px;
padding-top: 50px;
padding-left: 12%;
padding-right: 12%;
background-image: url('img/cardboardbright.jpg');
font-family: Montserrat;
}
#quote {
height: 800px;
background: grey;
}
#contact {
height: 325px;
}
#contactleft {
float: left;
height: 100%;
width: 12%;
background: white;
}
#contactmain {
float: left;
height: 100%;
width: 76%;
background: white;
}
#contactright {
float: left;
height: 100%;
width: 12%;
background: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div id="header">
<div id="navbar">
<div id="logo">
<img src="logosmall.png">
</div>
<ul id="top-menu">
<li class="active">
Home
</li>
<li>
Services
</li>
<li>
Moving Tips
</li>
<li>
Get A Quote
</li>
<li>
Contact Us
</li>
</ul>
</div>
</div>
<div id="home">
Content Here.
</div>
<div id="services">
<div id="servicesleft"></div>
<div id="servicesmain">
<div id="movessec">
Content Here.
</div>
<div id="movessec">
Content Here.
</div>
<div id="movessec">
Content Here.
</div>
</div>
<div id="servicesright"></div>
</div>
<div id="moving">Content here.</div>
<div id="quote">Quote form goes here.</div>
<div id="contact">
<div id="contactleft">Content Here</div>
<div id="contactmain">Content Here</div>
<div id="contactright">Content Here</div>
</div>
</body>
You could move the change of the active class to the click, here i have commented out the change that happens on scroll, moved it to the click event, and also added a line to get the id:
window.onload=function(){
// Cache selectors
var lastId,
topMenu = $("#top-menu"),
topMenuHeight = topMenu.outerHeight()+15,
// All list items
menuItems = topMenu.find("a"),
// Anchors corresponding to menu items
scrollItems = menuItems.map(function(){
var item = $($(this).attr("href"));
if (item.length) { return item; }
});
// Bind click handler to menu items
// so we can get a fancy scroll animation
menuItems.click(function(e){
var href = $(this).attr("href"),
id = href.split('#')[1],
offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1;
$('html, body').stop().animate({
scrollTop: offsetTop
}, 300);
e.preventDefault();
menuItems.parent().removeClass("active").end().filter("[href='#"+id+"']").parent().addClass("active");
});
// Bind to scroll
$(window).scroll(function(){
// Get container scroll position
var fromTop = $(this).scrollTop()+topMenuHeight;
// Get id of current scroll item
var cur = scrollItems.map(function(){
if ($(this).offset().top < fromTop)
return this;
});
// Get the id of the current element
cur = cur[cur.length-1];
var id = cur && cur.length ? cur[0].id : "";
if (lastId !== id) {
lastId = id;
// Set/remove active class
//menuItems
// .parent().removeClass("active")
// .end().filter("[href='#"+id+"']").parent().addClass("active");
}
});
}//]]>
#font-face {
font-family: 'Montserrat';
src: url('fonts/Montserrat-Regular.otf')
}
#font-face {
font-family: 'MontserratSlim';
src: url('fonts/Montserrat-ExtraLight.otf')
}
body {
font-family: Helvetica, Arial;
margin: 0px;
}
#header {
top: 0px;
}
.signsize {
width: 140px;
height: 90px;
}
.movesimg {
float: right;
}
.packing {
float: left;
}
h1 {
font-family: 'Montserrat';
font-size: 50px;
text-align: right;
color: #3d3d3d;
margin:0;
}
h2 {
margin: 0;
color: #3d3d3d;
}
h3 {
color: #3d3d3d;
}
h4 {
font-family: 'Montserrat';
font-size: 50px;
text-align: left;
color: #3d3d3d;
margin:0;
}
h5 {
font-size: 50px;
padding-top: 60px;
color: #3d3d3d;
margin: 0;
}
h6 {
font-family: 'MontserratSlim';
font-size: 15px;
text-align: left;
color: #929292;
margin:0;
}
#descriptionl {
font-family: 'MontserratSlim';
font-size: 15px;
color: #929292;
margin:0;
}
#descriptionr {
font-family: 'MontserratSlim';
font-size: 15px;
color: #929292;
text-align: right;
margin:0;
}
#movessec {
display: inline-block;
padding-top: 60px;
padding-bottom: 60px;
border-bottom: solid thin #d8d8d8;
}
#navbar {
position: fixed;
z-index: 1;
background: white;
right: 0px;
top: 0px;
width: 100%;
}
#logo {
float: left;
margin-left: 10%;
padding-top: 10px;
padding-bottom: 10px;
}
#top-menu {
z-index: 1;
float: right;
padding-right: 10%;
padding-top: 25px;
padding-bottom: 25px;
}
#top-menu li {
float: left;
list-style-type: none;
white-space: nowrap;
font-size: 15px;
font-family: Montserrat;
text-transform: uppercase;
font-weight: 600;
text-align: center;
letter-spacing: 1px;
}
#more {
padding-left: 50px;
}
#moreR {
padding-right: 50px;
}
#more li {
float: left;
list-style-type: none;
white-space: nowrap;
font-size: 15px;
font-family: Montserrat;
text-transform: uppercase;
font-weight: 600;
text-align: center;
letter-spacing: 1px;
padding: 8px;
outline: #4690d4 solid thin;
text-decoration: none;
}
#moreR li {
float: right;
list-style-type: none;
white-space: nowrap;
font-size: 15px;
font-family: Montserrat;
text-transform: uppercase;
font-weight: 600;
text-align: center;
letter-spacing: 1px;
padding: 8px;
outline: #4690d4 solid thin;
text-decoration: none;
}
#top-menu a {
display: inline;
width: 6em;
text-align: center;
padding: 15px;
-webkit-transition: .5s all ease-out;
-moz-transition: .5s all ease-out;
transition: .5s all ease-out;
color: #545454;
text-decoration: none;
letter-spacing: 1px;
}
#top-menu a:hover {
color: #575757;
}
#top-menu li.active a {
color: white;
position: relative;
background: #4690d4;
}
#home {
padding-left: 70px;
padding-top: 150px;
height: 800px;
background-image: url(img/movingboxes.jpg);
background-size: cover;
background-repeat: no-repeat;
font-family: Montserrat;
}
#services {
height: 1600px;
}
#servicesleft {
float: left;
height: 100%;
width: 12%;
}
#servicesmain {
float: left;
height: 100%;
width: 76%;
}
#servicesright {
float: left;
height: 100%;
width: 12%;
}
#moving {
height: 800px;
padding-top: 50px;
padding-left: 12%;
padding-right: 12%;
background-image: url('img/cardboardbright.jpg');
font-family: Montserrat;
}
#quote {
height: 800px;
background: grey;
}
#contact {
height: 325px;
}
#contactleft {
float: left;
height: 100%;
width: 12%;
background: white;
}
#contactmain {
float: left;
height: 100%;
width: 76%;
background: white;
}
#contactright {
float: left;
height: 100%;
width: 12%;
background: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div id="header">
<div id="navbar">
<div id="logo">
<img src="logosmall.png">
</div>
<ul id="top-menu">
<li class="active">
Home
</li>
<li>
Services
</li>
<li>
Moving Tips
</li>
<li>
Get A Quote
</li>
<li>
Contact Us
</li>
</ul>
</div>
</div>
<div id="home">
Content Here.
</div>
<div id="services">
<div id="servicesleft"></div>
<div id="servicesmain">
<div id="movessec">
Content Here.
</div>
<div id="movessec">
Content Here.
</div>
<div id="movessec">
Content Here.
</div>
</div>
<div id="servicesright"></div>
</div>
<div id="moving">Content here.</div>
<div id="quote">Quote form goes here.</div>
<div id="contact">
<div id="contactleft">Content Here</div>
<div id="contactmain">Content Here</div>
<div id="contactright">Content Here</div>
</div>
</body>
By setting a min-height to 100vh you can make sure it is always at least the height of the user's screen.
I am new to jQuery and I am facing an issue with addClass() on a scroll event. Here is my code:
HTML:
<div class="sidebar">
<ul>
<li id="pop">Home</li>
<li>Programs</li>
<li>Replay</li>
</ul>
</div>
CSS:
.sidebar div {
width: 150px;
height: 250px;
float: right;
position: fixed;
z-index: 1;
}
.sidebar ul {
list-style-type: none;
padding-left: 0;
position: fixed;
}
.sidebar li {
background: gray;
color: white;
text-transform: uppercase;
font-size: 13px;
width: 80px;
}
.active {
width: 140px;
background: orange;
font-size: 25px;
}
jQuery:
$(document).ready(function() {
$(window).scroll(function() {
var st = $(this).scrollTop();
if( st > 500 ) {
$("#pop").addClass("active");
} else {
$("#pop").removeClass("active");
}
});
});
I have also tried to use toggleClass() without any success. I can't figure out what what is preventing it from working.
Thank you in advance for your help.
Change like this :
Css :
Remove this :
.sidebar li {
background: gray;
color: white;
text-transform: uppercase;
font-size: 13px;
width: 80px;
}
And add :
.normal {
font-size: 13px;
background: gray;
color: white;
text-transform: uppercase;
width: 80px;
}
.active {
width: 140px;
background-color:orange;
font-size: 25px;
text-transform: uppercase;
color: white;
}
Html :
Add class normal to lis
<ul>
<li id="pop" class="normal">Home</li>
<li class="normal">Programs</li>
<li class="normal">Replay</li>
</ul>
Jquery :
$(document).ready(function(){
$(window).on("scroll",function() {
if($(this).scrollTop() > 500)
$("#pop").removeClass("normal").addClass("active");
else
$("#pop").removeClass("active").addClass("normal");
})
})
Final code :
<html>
<title>This is test</title>
<head>
<style>
body {
height: 2500px;
}
.sidebar div {
width: 150px;
height: 250px;
float: right;
position: fixed;
z-index: 1;
}
.sidebar ul {
list-style-type: none;
padding-left: 0;
position: fixed;
}
.normal {
font-size: 13px;
background: gray;
color: white;
text-transform: uppercase;
width: 80px;
}
.active {
width: 140px;
background-color:orange;
font-size: 25px;
text-transform: uppercase;
color: white;
}
</style>
</head>
<body>
<div class="sidebar">
<ul>
<li id="pop" class="normal">Home</li>
<li class="normal">Programs</li>
<li class="normal">Replay</li>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(window).on("scroll",function() {
if($(this).scrollTop() > 500)
$("#pop").removeClass("normal").addClass("active");
else
$("#pop").removeClass("active").addClass("normal");
})
})
</script>
</body>
</html>
Be more specific with your css:
<style>
div.sidebar li.active {
width: 140px;
background: orange;
font-size: 25px;
}
</style>
https://jsfiddle.net/o266wh3r/1/