Skip to content

Commit

Permalink
Scrollbar width
Browse files Browse the repository at this point in the history
  • Loading branch information
gotpop committed Oct 31, 2022
1 parent 1bc33f9 commit ed4e3d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/layouts/Site.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
overflow: hidden;
transition: translate var(--timing) ease;
translate: var(--menu-state);
width: calc(100vw + var(--menu-side-width));
width: calc(100vw + var(--menu-side-width) - var(--scrollbar-width));

@media (--ipad) {
grid-template-areas:
Expand Down
17 changes: 10 additions & 7 deletions src/layouts/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import React, { useContext, useEffect } from 'react'
import React, { useEffect } from 'react'
import Head from 'next/head'
import Header from '@components/Header'
import Footer from '@components/Footer'
// import MenuContext from '@context/MenuContext'
import Trigger from '@components/Trigger'
import styles from './Site.module.css'

const getScrollBarWidth = () => {
let root = document.documentElement
const width = window.innerWidth - root.clientWidth

root.style.setProperty('--scrollbar-width', `${width}px`)
}

export default function Layout(props) {
const { children } = props
// const { menu } = useContext(MenuContext)

useEffect(() => {
document.documentElement.style.setProperty(
'--scrollbar-width',
window.innerWidth - document.documentElement.clientWidth + 'px'
)
getScrollBarWidth()
}, [])

return (
<>
<Head>
<title>CSS 2023</title>
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
</Head>
<div className={styles.site}>
<Header />
Expand Down

0 comments on commit ed4e3d6

Please sign in to comment.