Skip to content

Commit

Permalink
style: Change header background colour on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
AnisioMandlate committed Feb 16, 2021
1 parent 117e668 commit 65aeece
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/components/Header/index.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import { Link } from "gatsby"
import PropTypes from "prop-types"
import React from "react"
import React, { useState, useEffect } from "react"

import styles from "./styles.module.css"
import logo from "../../images/payments.png"

const Header = ({ siteTitle }) => {
const [className, setClassName] = useState("")

useEffect(() => {
window.addEventListener("scroll", handleScroll)
return () => {
window.removeEventListener("scroll", handleScroll, true)
}
}, [])

const handleScroll = () => {
window.pageYOffset > 135 ? setClassName("scroll") : setClassName("")
}

return (
<header>
<header className={styles[className]}>
<div className={styles.menu}>
<Link to="/">
<h1>
Expand Down
8 changes: 6 additions & 2 deletions src/components/Header/styles.module.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
header {
position: sticky;
background: #1a2730;
background: #18242c00;
top: 0;
border-bottom: 1px solid #1a2730;
}

header.scroll {
z-index: 999;
background: #18242cf7;
}

.menu {
Expand Down

0 comments on commit 65aeece

Please sign in to comment.