Currently, I am designing a pretend blog layout to showcase my work. The grid of posts features cards that are precisely 400x400 in size with a hover effect that magnifies and adds a drop shadow (this is visible in the dashboard route).
However, an issue arises when scrolling through the page as the cursor tends to get stuck on the cards, halting the scroll functionality during the animation. While researching a solution, I stumbled upon an article () which discusses the performance advantages of disabling pointer events to the body while scrolling. Unfortunately, I am having trouble implementing this concept in React.
Is there a way to apply a class to the document body only while scrolling in React and remove it once the scrolling ceases? Possibly using a setTimeout
method? I fear that such an approach might be inelegant...
I have provided the code where I intend to integrate this behavior. Although uncertain if it will provide clarity, the existing scroll event setup is designed to maintain page position as the navbar extends.
export default class Layout extends Component {
// Code snippet here
}
As an attempt to resolve this, I experimented with setting
document.body.style.pointerEvents = 'auto'
in the componentDidMount()
method and then disabling it within handleScrollY()
. However, this approach proved ineffective since the pointer events were not restored post-scroll event. Similarly, I tested placing the logic in componentDidUpdate()
, but encountered issues since no component was updating while the scrolling event wasn't active.