Answers for "nav in js"

CSS
2

sticky operations in javascript

var siteHeader = document.getElementById('siteHeader'),
    siteNav = document.getElementById('siteNav');

    window.onscroll = function() {
        if ( siteNav.offsetTop < document.documentElement.scrollTop + 26 || siteNav.offsetTop < document.body.scrollTop + 26) {
            siteHeader.setAttribute("class","sticky");
        }
        else {
            siteHeader.setAttribute("class","");
        }
    }
Posted by: Guest on December-01-2020
0

nav js

document.getElementById('open').addEventListener('click', open);
document.getElementById('close').addEventListener('click', close);
var nav = document.getElementById('nav');
var close = document.getElementById('close');
function open() {
    nav.style.width = "100%";
    setTimeout(
        function (){
            document.getElementById('close').style.display = "block";
        }, 170);
}

function close(){
    nav.style.width = "0";
    close.style.display = "none";
}
Posted by: Guest on July-08-2020

Browse Popular Code Answers by Language