Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

fixed menu reactjs

import { useEffect, useState } from "react";

    const NavBar = () => {
    // sticky nav
    const [stickyClass, setStickyClass] = useState("");

    function stickNavbar() {
        let windowHeight = window.scrollY;
        setStickyClass("sticky-nav") ? windowHeight > 500 : setStickyClass("");
    }

    useEffect(() => {
        window.addEventListener("scroll", stickNavbar);
    }, []);

return (
        <nav className="relative w-full p-4">
            <div className={`flex w-full flex-row items-center justify-between ${stickyClass}`}>
             navbar content goes here ....
            <div/>
<nav/>
Comment

how to properly make the navbar to be fixed to the top in react.jsx

Sticky Navbar
Comment

PREVIOUS NEXT
Code Example
Javascript :: protected route in react js 
Javascript :: reverse words in a string javascript 
Javascript :: cypress command return value into variable 
Javascript :: iterate through array js 
Javascript :: basic express graphql 
Javascript :: javascript format date 
Javascript :: js how to reverse a string 
Javascript :: set background color dynamically javascript 
Javascript :: npm react pagination 
Javascript :: js create json array 
Javascript :: cypress check attribute for each element 
Javascript :: express get query parameters 
Javascript :: convert queryset to json django 
Javascript :: expo custom fonts 
Javascript :: angular ngfor counter 
Javascript :: js copy to clipboard 
Javascript :: reactnode prop-types 
Javascript :: JavaScript Use clearInterval() Method 
Javascript :: replace all character in string javascript 
Javascript :: nested object javascript 
Javascript :: json limit 
Javascript :: reactjs get url query params as object 
Javascript :: chocolatey nodejs 
Javascript :: fetch function javascript 
Javascript :: find positive integers javascript 
Javascript :: node module es6 
Javascript :: time js code 
Javascript :: firebase timestamp to date angular 
Javascript :: multiply function javascript 
Javascript :: csv to json python 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =