initial commit

This commit is contained in:
2022-01-22 16:37:32 +01:00
commit a494abf762
6 changed files with 90 additions and 0 deletions

31
react-modules/ScrollTopButton.js vendored Normal file
View File

@@ -0,0 +1,31 @@
import React, {useState} from 'react'
export const ScrollTopButton = () => {
const [visible, setVisible] = useState(false)
const toggleVisible = () => {
const scrolled = document.documentElement.scrollTop
if (scrolled > 300) {
setVisible(true)
} else if (scrolled <= 300) {
setVisible(false)
}
}
const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
})
}
window.addEventListener('scroll', toggleVisible)
return (
<i
className="bi bi-arrow-up-square scroll-top-btn text-info"
onClick={() => scrollToTop()}
style={{display: visible ? 'inline' : 'none'}}
/>
)
}