Light Weight Responsive Navigation (No extra HTML + Pure non-obtrusive Javascript)

Developer
Size
3,681 Kb
Views
44,528

How do I make an light weight responsive navigation (no extra html + pure non-obtrusive javascript)?

Here is a demonstration of the lightweight responsive navigation we just created. It uses no extra HTML markup, has no external dependencies, and will work whether JavaScript is enabled or not.. What is a light weight responsive navigation (no extra html + pure non-obtrusive javascript)? How do you make a light weight responsive navigation (no extra html + pure non-obtrusive javascript)? This script and codes were developed by Robby Klein on 07 July 2022, Thursday.

Light Weight Responsive Navigation (No extra HTML + Pure non-obtrusive Javascript) Previews

Light Weight Responsive Navigation (No extra HTML + Pure non-obtrusive Javascript) - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Light Weight Responsive Navigation (No extra HTML + Pure non-obtrusive Javascript)</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <header> <div class="topWidth"> <h1 class="header"> <a href="#">Sitechop.com</a> </h1> <nav id="nav" class="hide"> <ul> <li><a href="#">Home</a></li> <li><a href="#">Blog</a></li> <li><a href="#">Portfolio</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </nav> </div> </header> <div class="width"> <article> <h2>Lightweight Responsive Navigation Demo</h2> <p>Above is a demonstration of the lightweight responsive navigation we just created. It uses no extra HTML markup, has no external dependencies, and will work whether JavaScript is enabled or not.</p> <p><a target="_blank" href="http://sitechop.com/front-end/responsive-navigation-tutorial">Return to post</a> | <a target="_blank" href="http://sitechop.com">Return home</a></p> </article> </div>
<!-- This would normally go in a linked external stylesheet, wrapped in <noscript> tags, just below our main CSS file. Can't do that on codepen so I placed it here. Try fullscreen mode with JS disabled to check it out. -->
<noscript><style>
@media only screen and (max-width: 46.938em) { h1 { width: 100%; text-align: center; margin: 0; } nav { display: block; padding: 0 0 1em 0; float: none; line-height: 2; padding-top: 3.75em; } nav ul, nav a { border: none; } nav a { padding: 0; margin: 0 0.75em; } nav a:hover { background: none; } nav li { display: inline-block; }
}
</style></noscript> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Light Weight Responsive Navigation (No extra HTML + Pure non-obtrusive Javascript) - Script Codes CSS Codes

/* Ignore this */
@import url(http://sitechop.com/codepen/codepen1.css);
/* End Ignore */
/* ////////////////////////////////// */
/* ///// Page Styles */
/* ////////////////////////////////// */
html,body,h1,ul,li,div,a,p,button { margin:0; padding:0;
}
body { font:normal 100%/165% arial, helvetica, sans-serif;
}
a { text-decoration: none; font-weight: bold;
}
article { margin-top: 2.5em;
}
article a { color: #2980b9
}
p { color: #747474;
}
p+p { margin-top: 1.5em;
}
h2 { line-height: 1.35;
}
.width { max-width: 62.25em; width: 90%; margin: 0 auto;
}
/* ////////////////////////////////// */
/* // Responsive Navigation Styles */
/* ////////////////////////////////// */
header { min-height: 3.75em; background: #34495e; background-repeat: repeat-x; background-size:100% 3.75em; background-image: -webkit-linear-gradient(top, #425f7c, #34495e); background-image: -moz-linear-gradient(top, #425f7c, #34495e); background-image: -ms-linear-gradient(top, #425f7c, #34495e); background-image: -o-linear-gradient(top, #425f7c, #34495e); background-image: linear-gradient(top, #425f7c, #34495e); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#425f7c', endColorstr='#34495e',GradientType=0 );
}
.topWidth { max-width: 62.25em; margin: 0 auto;
}
.header { position: absolute; margin-left: 5%; font-size: 1.5em; line-height: 2.5;
}
.header a { color: white;
}
button { float: right; background: none; border: none; font-size: 1em; color: white; font-weight: bold; line-height: 3.75; margin-right: 5%;
}
nav { padding-top: 3.75em; text-align: center; display: none;
}
nav ul { border-top: 1px solid #293949;
}
nav li { list-style: none;
}
nav a { display: block; color: #d5dfe8; padding: 0.75em 0; border-bottom: 1px solid #293949;
}
nav a:hover { background-color: #293949; color: white;
}
.show { display: block; transition: .3s;
}
@media only screen and (min-width: 740px) { .topWidth { width: 90%; } .header { margin: 0; } #menu { display: none; } nav { display: block; padding: 0; text-align: inherit; float: right; line-height: 3.75; } nav ul, nav a { border: none; } nav a { padding: 0; margin-left: 2em; } nav a:hover { background: none; } nav li { display: inline-block; }
}

Light Weight Responsive Navigation (No extra HTML + Pure non-obtrusive Javascript) - Script Codes JS Codes

//Create menu button
var menu = document.createElement("button");
menu.id = "menu";
menu.innerHTML = "Menu";
// Insert After Function
function insertAfter(referenceNode, newNode) { referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
// Header Variable
var header = document.getElementsByTagName("h1")[0];
// Inject Menu Button
insertAfter(header, menu);
// Navigation list variable
var nav = document.getElementById('nav');
// Toggle class function
function toggleClass(element, className){ if (!element || !className){ return; } var classString = element.className, nameIndex = classString.indexOf(className); if (nameIndex == -1) { classString += ' ' + className; } else { classString = classString.substr(0, nameIndex) + classString.substr(nameIndex+className.length); } element.className = classString;
}
menu.addEventListener('click', function() { toggleClass(nav, 'show');
});
// Ignore This
$.getScript("http://sitechop.com/codepen/codepen1.js", function(){});
Light Weight Responsive Navigation (No extra HTML + Pure non-obtrusive Javascript) - Script Codes
Light Weight Responsive Navigation (No extra HTML + Pure non-obtrusive Javascript) - Script Codes
Home Page Home
Developer Robby Klein
Username robbyklein
Uploaded July 07, 2022
Rating 3.5
Size 3,681 Kb
Views 44,528
Do you need developer help for Light Weight Responsive Navigation (No extra HTML + Pure non-obtrusive Javascript)?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Robby Klein (robbyklein) Script Codes
Create amazing SEO content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!