diff --git a/src/components/Navbar/Navbar.jsx b/src/components/Navbar/Navbar.jsx index ebbadb5..d383a80 100755 --- a/src/components/Navbar/Navbar.jsx +++ b/src/components/Navbar/Navbar.jsx @@ -1,5 +1,4 @@ import { scb as logo } from '../../assets/images'; -import { NavLink } from "react-router-dom"; import NavbarLink from './NavbarLink'; import './Navbar.styles.scss'; diff --git a/src/components/Navbar/Navbar.styles.scss b/src/components/Navbar/Navbar.styles.scss index 5c1bd01..e71c4cf 100755 --- a/src/components/Navbar/Navbar.styles.scss +++ b/src/components/Navbar/Navbar.styles.scss @@ -1,13 +1,13 @@ @import "../../assets/styles/theme.scss"; .navbar { - position: absolute; + position: fixed; top: 0; width: 80%; height: 60px; max-height: 80px; padding: 1em 10%; - background: transparent; + background: $bg-secondary; z-index: 1; display: flex; @@ -43,4 +43,9 @@ background: $text-secondary; } } +} + +.navbar.absolute { + position: absolute; + background: transparent; } \ No newline at end of file diff --git a/src/lib/useElementOnScreen.js b/src/lib/useElementOnScreen.js new file mode 100644 index 0000000..78084b5 --- /dev/null +++ b/src/lib/useElementOnScreen.js @@ -0,0 +1,30 @@ +import { useRef, useEffect, useState } from "react"; + +const useElementOnScreen = (options) => { + + const containerRef = useRef(null); + const [isVisible, setIsVisible] = useState(false); + + const observerCallback = (entries) => { + const [entry] = entries; + setIsVisible(entry.isIntersecting); + }; + + useEffect(() => { + const observer = new IntersectionObserver(observerCallback, options); + + if (containerRef.current) { + observer.observe(containerRef.current); + } + + return () => { + if (containerRef.current) { + observer.unobserve(containerRef.current); + } + } + }, [containerRef, options]) + + return [containerRef, isVisible]; +} + +export default useElementOnScreen; \ No newline at end of file diff --git a/src/pages/Main/Main.jsx b/src/pages/Main/Main.jsx index 82b017b..40d021b 100755 --- a/src/pages/Main/Main.jsx +++ b/src/pages/Main/Main.jsx @@ -1,11 +1,29 @@ +import { useEffect } from 'react'; + import { News, Projects, Labs, Partners, Gallery, ContactUs } from './components'; +import useElementOnScreen from '../../lib/useElementOnScreen'; function Main() { + const [containerRef, isVisible] = useElementOnScreen({ + root: null, + rootMargin: '0px', + threshold: 0, + }); + + useEffect(() => { + const [ navbar ] = document.getElementsByClassName('navbar'); + if (isVisible) { + navbar.classList.add('absolute'); + } else { + navbar.classList.remove('absolute'); + } + }, [isVisible]); + return ( <> -
+

Думай иначе, будь креативным!

-

Студенческое конструкторское бюро
+

Студенческое конструкторское бюро
"Компьютерное инновационное творчество"

Связаться с нами