Fixed document scroll position when modal opened
This commit is contained in:
parent
03024ca58d
commit
d0c0f3ab93
|
@ -49,9 +49,24 @@ export const Header = (props: Props) => {
|
||||||
const toggleWarnings = () => setVisibleWarnings(!visibleWarnings())
|
const toggleWarnings = () => setVisibleWarnings(!visibleWarnings())
|
||||||
const toggleFixed = () => setFixed((oldFixed) => !oldFixed)
|
const toggleFixed = () => setFixed((oldFixed) => !oldFixed)
|
||||||
// effects
|
// effects
|
||||||
|
|
||||||
|
let windowScrollTop = 0
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
|
const mainContent = document.querySelector('.main-content')
|
||||||
|
|
||||||
|
if (fixed() || modal() !== null) {
|
||||||
|
windowScrollTop = window.scrollY
|
||||||
|
mainContent.style.marginTop = `-${windowScrollTop}px`
|
||||||
|
}
|
||||||
|
|
||||||
document.body.classList.toggle('fixed', fixed() || modal() !== null)
|
document.body.classList.toggle('fixed', fixed() || modal() !== null)
|
||||||
document.body.classList.toggle(styles.fixed, fixed() && !modal())
|
document.body.classList.toggle(styles.fixed, fixed() && !modal())
|
||||||
|
|
||||||
|
if (!fixed() && !modal()) {
|
||||||
|
mainContent.style.marginTop = ''
|
||||||
|
window.scrollTo(0, windowScrollTop)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// derived
|
// derived
|
||||||
|
|
|
@ -565,7 +565,6 @@ astro-island {
|
||||||
min-height: 300px;
|
min-height: 300px;
|
||||||
padding-top: 100px;
|
padding-top: 100px;
|
||||||
position: relative;
|
position: relative;
|
||||||
transition: all 1s ease;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.main-content--no-padding {
|
.main-content--no-padding {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user