-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not working on gatsby v2 #8
Comments
Have you configured your |
Yes, I added it in |
Hey @vlinas! Can you share your |
Hey @solubletech , here's my
|
@solubletech I found the issue here. Scroll reveal doesn't work if div is wrapped in react-lazyload component |
I'm having the same issue as well using Styled Components. Could that cause an issue? Gatsby Config:
|
@vlinas @DRD161 You might have better luck with a different solution. There's nothing Gatsby-specific about this behavior, and the dependency doing the heavy lifting uses a very non-React approach, leading to some of the issues you're experiencing with client-side rendered elements (e.g. LazyLoad) or JS-based CSS solutions (StyledComponents). Here's an example using a lightweight Intersection Observer wrapper: import { useInView } from "react-intersection-observer"
const AnimateIn = ({ threshold = 0.15, triggerOnce = false, ...remainingProps }) => {
const [ref, inView] = useInView({ threshold, triggerOnce })
return (
<div
style={{
// adjust these as desired
transition: "opacity 300ms, transform 300ms",
opacity: inView ? 1 : 0,
transform: `translateY(${inView ? 0 : 100}px)`,
}}
{...remainingProps}
/>
)
} Then just wrap any components you want entrance animations on with this component, overriding the default <AnimateIn triggerOnce={true}>
<h1>Hi Mom!</h1>
</AnimateIn> This is much easier to reason about, doesn't couple itself to Gatsby, and you can easily extend or modify it to do anything else you need, all without adding a bunch of additional dependencies to your client-side code. You can even use this approach to auto-play videos when they're in view and pause them when they're not: import { useInView } from "react-intersection-observer"
const AutoPlayingVideo = ({ threshold = 0.15, ...playerProps }) => {
const [ref, inView] = useInView({ threshold })
useEffect(() => {
if (inView) {
ref.current?.play()
} else {
ref.current?.pause()
}
}, [ref, inView])
return (
<video
style={{
transition: "opacity 300ms, transform 300ms",
opacity: inView ? 1 : 0,
transform: `translateY(${inView ? 0 : 100}px)`,
}}
ref={ref}
autoPlay
playsInline
muted
loop
{...playerProps}
/>
)
} |
Hey guys, I can't make this plugin to work...
When I import sal.css from node_modules every div with data-sal properties just disappear. Am I missing something?
The text was updated successfully, but these errors were encountered: