I’m currently using the data-aos
attribute to apply the "fade-up-right" animation to an element in my web page, like this:
<div className="des__Container" data-aos="fade-up-right">
Now, I want to change the animation specifically when the screen width is at its maximum of 768 pixels.
Is it possible to conditionally modify this animation based on the screen width? If not, are there any alternative solutions or best practices for achieving this?
Any guidance would be greatly appreciated. Thanks in advance!
3
Answers
You can achieve this by adding CSS media queries to the animation. You can try the following code:
Here’s an approach
You can create a custom hook called useWindowSize which gives you width of the window and then inside your div, you can conditionally add/remove data-aos:
Code for hook:
Code sandbox:
https://codesandbox.io/s/fervent-flower-8gln2c?file=/hooks/useWindowSize.js:0-758