mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 04:17:23 +00:00
Improve Floating To Top button visibility logic based on scroll direction
This commit is contained in:
@@ -276,12 +276,14 @@ function FloatingToTopButton() {
|
|||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
let lastScrollY = window.scrollY;
|
||||||
|
|
||||||
const handleScroll = () => {
|
const handleScroll = () => {
|
||||||
if (window.scrollY > 200) {
|
const isScrollingUp = window.scrollY < lastScrollY;
|
||||||
setVisible(true);
|
const isAboveThreshold = window.scrollY > 200;
|
||||||
} else {
|
|
||||||
setVisible(false);
|
setVisible(isScrollingUp && isAboveThreshold);
|
||||||
}
|
lastScrollY = window.scrollY;
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("scroll", handleScroll);
|
window.addEventListener("scroll", handleScroll);
|
||||||
|
Reference in New Issue
Block a user