One page Website
One page Website with smooth scrolling and hide hash from url
Css
<style>
html, body {
margin:0;
padding:0;
width:100%;
font-size:1em;
color:#ffffff;
}
#header {
height:80px;
background:#1240AB;
padding:20px;
border-bottom:3px solid #4671D5;
}
#subMenu {
height:50px;
width:inherit;
background:#6c8cd5;
display:none;
position:fixed;
top:0;
left:0;
z-index:500;
opacity:.9;
padding:15px;
}
#content {
margin:20px;
font-size:2.25em;
color:#232323;
height: 1000px;
}
#content h1 {
font-size: 20px;
margin: 0 auto;
padding-top: 5%;
text-align: center;
}
section {
min-height: 100%;
}
.main {
height: 100%;
}
li {
color: #000;
display: inline-block;
font-size: 16px;
}
li a {color: #fff; text-decoration: none;}
</style>
html, body {
margin:0;
padding:0;
width:100%;
font-size:1em;
color:#ffffff;
}
#header {
height:80px;
background:#1240AB;
padding:20px;
border-bottom:3px solid #4671D5;
}
#subMenu {
height:50px;
width:inherit;
background:#6c8cd5;
display:none;
position:fixed;
top:0;
left:0;
z-index:500;
opacity:.9;
padding:15px;
}
#content {
margin:20px;
font-size:2.25em;
color:#232323;
height: 1000px;
}
#content h1 {
font-size: 20px;
margin: 0 auto;
padding-top: 5%;
text-align: center;
}
section {
min-height: 100%;
}
.main {
height: 100%;
}
li {
color: #000;
display: inline-block;
font-size: 16px;
}
li a {color: #fff; text-decoration: none;}
</style>
javascript
<script>
$(document).ready(function() {
var headerTop = $('#header').offset().top;
var headerBottom = headerTop + 120; // Sub-menu should appear after this distance from top.
$(window).scroll(function () {
var scrollTop = $(window).scrollTop(); // Current vertical scroll position from the top
if (scrollTop > headerBottom) { // Check to see if we have scrolled more than headerBottom
if (($("#subMenu").is(":visible") === false)) {
$('#subMenu').fadeIn('slow');
}
} else {
if ($("#subMenu").is(":visible")) {
$('#subMenu').hide();
}
}
});
});
</script>
<script>
$(document).ready(function(){
// Add smooth scrolling to all links
$("a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
//window.location.hash = hash;
});
} // End if
});
});
</script>
$(document).ready(function() {
var headerTop = $('#header').offset().top;
var headerBottom = headerTop + 120; // Sub-menu should appear after this distance from top.
$(window).scroll(function () {
var scrollTop = $(window).scrollTop(); // Current vertical scroll position from the top
if (scrollTop > headerBottom) { // Check to see if we have scrolled more than headerBottom
if (($("#subMenu").is(":visible") === false)) {
$('#subMenu').fadeIn('slow');
}
} else {
if ($("#subMenu").is(":visible")) {
$('#subMenu').hide();
}
}
});
});
</script>
<script>
$(document).ready(function(){
// Add smooth scrolling to all links
$("a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
//window.location.hash = hash;
});
} // End if
});
});
</script>
Html
<div id="header"><ul><li><a href="#section1">Section Menu 1</a></li>
<li><a href="#section2">Section Menu 2</a></li>
<li><a href="#section3">Section Menu 3</a></li>
</ul></div>
<div id="subMenu">
<ul><li><a href="#section1">Section Menu 1</a></li>
<li><a href="#section2">Section Menu 2</a></li>
<li><a href="#section3">Section Menu 3</a></li>
</ul>
</div>
<div id="content">
<div class="main" id="section1">
<section style="background-color:#F0F8FF">
<h1> SECTION MENU 1 CONTENT </h1>
</section>
</div>
<div class="main" id="section2"style="background-color:#7FFFD4">
<h1> SECTION MENU 2 CONTENT</h1></section>
</div>
<div class="main" id="section3">
<section style="background-color:#00FFFF">
<h1> SECTION MENU 3 CONTENT</h1></section>
</div>
</div>
<li><a href="#section2">Section Menu 2</a></li>
<li><a href="#section3">Section Menu 3</a></li>
</ul></div>
<div id="subMenu">
<ul><li><a href="#section1">Section Menu 1</a></li>
<li><a href="#section2">Section Menu 2</a></li>
<li><a href="#section3">Section Menu 3</a></li>
</ul>
</div>
<div id="content">
<div class="main" id="section1">
<section style="background-color:#F0F8FF">
<h1> SECTION MENU 1 CONTENT </h1>
</section>
</div>
<div class="main" id="section2"style="background-color:#7FFFD4">
<h1> SECTION MENU 2 CONTENT</h1></section>
</div>
<div class="main" id="section3">
<section style="background-color:#00FFFF">
<h1> SECTION MENU 3 CONTENT</h1></section>
</div>
</div>
Complete Code
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<style>
html, body {
margin:0;
padding:0;
width:100%;
font-size:1em;
color:#ffffff;
}
#header {
height:80px;
background:#1240AB;
padding:20px;
border-bottom:3px solid #4671D5;
}
#subMenu {
height:50px;
width:inherit;
background:#6c8cd5;
display:none;
position:fixed;
top:0;
left:0;
z-index:500;
opacity:.9;
padding:15px;
}
#content {
margin:20px;
font-size:2.25em;
color:#232323;
height: 1000px;
}
#content h1 {
font-size: 20px;
margin: 0 auto;
padding-top: 5%;
text-align: center;
}
section {
min-height: 100%;
}
.main {
height: 100%;
}
li {
color: #000;
display: inline-block;
font-size: 16px;
}
li a {color: #fff; text-decoration: none;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<div id="header"><ul><li><a href="#section1">Section Menu 1</a></li>
<li><a href="#section2">Section Menu 2</a></li>
<li><a href="#section3">Section Menu 3</a></li>
</ul></div>
<div id="subMenu">
<ul><li><a href="#section1">Section Menu 1</a></li>
<li><a href="#section2">Section Menu 2</a></li>
<li><a href="#section3">Section Menu 3</a></li>
</ul>
</div>
<div id="content">
<div class="main" id="section1">
<section style="background-color:#F0F8FF">
<h1> SECTION MENU 1 CONTENT </h1>
</section>
</div>
<div class="main" id="section2"style="background-color:#7FFFD4">
<h1> SECTION MENU 2 CONTENT</h1></section>
</div>
<div class="main" id="section3">
<section style="background-color:#00FFFF">
<h1> SECTION MENU 3 CONTENT</h1></section>
</div>
</div>
<script>
$(document).ready(function() {
var headerTop = $('#header').offset().top;
var headerBottom = headerTop + 120; // Sub-menu should appear after this distance from top.
$(window).scroll(function () {
var scrollTop = $(window).scrollTop(); // Current vertical scroll position from the top
if (scrollTop > headerBottom) { // Check to see if we have scrolled more than headerBottom
if (($("#subMenu").is(":visible") === false)) {
$('#subMenu').fadeIn('slow');
}
} else {
if ($("#subMenu").is(":visible")) {
$('#subMenu').hide();
}
}
});
});
</script>
<script>
$(document).ready(function(){
// Add smooth scrolling to all links
$("a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
//window.location.hash = hash;
});
} // End if
});
});
</script>
</body>
</html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<style>
html, body {
margin:0;
padding:0;
width:100%;
font-size:1em;
color:#ffffff;
}
#header {
height:80px;
background:#1240AB;
padding:20px;
border-bottom:3px solid #4671D5;
}
#subMenu {
height:50px;
width:inherit;
background:#6c8cd5;
display:none;
position:fixed;
top:0;
left:0;
z-index:500;
opacity:.9;
padding:15px;
}
#content {
margin:20px;
font-size:2.25em;
color:#232323;
height: 1000px;
}
#content h1 {
font-size: 20px;
margin: 0 auto;
padding-top: 5%;
text-align: center;
}
section {
min-height: 100%;
}
.main {
height: 100%;
}
li {
color: #000;
display: inline-block;
font-size: 16px;
}
li a {color: #fff; text-decoration: none;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<div id="header"><ul><li><a href="#section1">Section Menu 1</a></li>
<li><a href="#section2">Section Menu 2</a></li>
<li><a href="#section3">Section Menu 3</a></li>
</ul></div>
<div id="subMenu">
<ul><li><a href="#section1">Section Menu 1</a></li>
<li><a href="#section2">Section Menu 2</a></li>
<li><a href="#section3">Section Menu 3</a></li>
</ul>
</div>
<div id="content">
<div class="main" id="section1">
<section style="background-color:#F0F8FF">
<h1> SECTION MENU 1 CONTENT </h1>
</section>
</div>
<div class="main" id="section2"style="background-color:#7FFFD4">
<h1> SECTION MENU 2 CONTENT</h1></section>
</div>
<div class="main" id="section3">
<section style="background-color:#00FFFF">
<h1> SECTION MENU 3 CONTENT</h1></section>
</div>
</div>
<script>
$(document).ready(function() {
var headerTop = $('#header').offset().top;
var headerBottom = headerTop + 120; // Sub-menu should appear after this distance from top.
$(window).scroll(function () {
var scrollTop = $(window).scrollTop(); // Current vertical scroll position from the top
if (scrollTop > headerBottom) { // Check to see if we have scrolled more than headerBottom
if (($("#subMenu").is(":visible") === false)) {
$('#subMenu').fadeIn('slow');
}
} else {
if ($("#subMenu").is(":visible")) {
$('#subMenu').hide();
}
}
});
});
</script>
<script>
$(document).ready(function(){
// Add smooth scrolling to all links
$("a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
//window.location.hash = hash;
});
} // End if
});
});
</script>
</body>
</html>
Comments
Post a Comment