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 :: country select dropdown javascript 
Javascript :: climbing stairs 
Javascript :: Backbone Template Simple Example 
Javascript :: Top Tips for Vue 3 Development 
Javascript :: discord.js profile picture 
Javascript :: Initialize View With Collection Backbone 
Javascript :: run javascript after rendering 
Javascript :: add seconds to date 
Javascript :: how to decrypt md5 hash 
Javascript :: password generator and password strength using javascript 
Javascript :: clear console javascript 
Javascript :: javascript filter array of object by id 
Javascript :: higher order function javascript 
Javascript :: moment now 
Javascript :: sort list in javascript 
Javascript :: js duplicate 
Javascript :: events js 
Javascript :: chatbot js 
Javascript :: suitescript dialog box 
Javascript :: why null is an object in javascript 
Javascript :: Convert to String Explicitly 
Javascript :: javascript Benefit of Using Symbols in Object 
Javascript :: fetch second parameters 
Javascript :: JavaScript Validation API 
Javascript :: what is hmr in console 
Javascript :: fingerprint2 
Javascript :: adding transition to collapse button js 
Javascript :: phaser generate frame names 
Javascript :: Exercice âge JavaScript 
Javascript :: 555 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =