Framer motion with disable javascript #1792
-
I am using framer motion on nextjs and build it as static site. My question is there any way to configure on framer motion to display the content directly if javascript is disabled on the page? Example website: https://go-tailwind.preview.uideck.com/ |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
You can use the fallbackStyle property of the Framer Motion animate component to specify styles that will be applied to the component if JavaScript is disabled. These styles will be applied directly to the element, so the animation will not run, but the element will still be visible on the page. Here is an example of how to use the fallbackStyle property:
You can also use the initial property to specify the starting styles for the element, which will be applied directly to the element if JavaScript is disabled. This can be useful for ensuring that the element is visible and in the correct position on the page even if the animation does not run. Here is an example of how to use the initial property:
I hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Hi guys, in case that in 2023 someone still have this problem here is how I manage it: I declare a constant to see if JS is enabled: Then I use it to see what kind of initial state apply: <motion.div
initial={
isJavaScriptEnabled
? { opacity: 0, scale: 0.9 }
: { opacity: 1, scale: 1 }
}
animate={ { opacity: 1, scale: 1 } }
>
{/* ... content here... */}
</motion.div> Hope this worked and if someone found another better solution please let us know! |
Beta Was this translation helpful? Give feedback.
-
Hi ppl. As users pointed out above, the This is my current (not so elegant) solution to this: Add a class to the motion component, like this: <noscript>
<style>
.motion { opacity: 1 !important }
</style>
</noscript> This is working fine to me. And no problems with SSR. Obs: Full respect for libs authors, but majority of JS libs doesn't offer a solution/little-guide for NO-JS situations. That is kinda sad, cause there are a lot of situations where this is important. We expect good web apps works even without JS, at least a limited experience (Optimistic UX). We are not talking about ancient browsers, just plain modern HTML/CSS. Sorry for the little rant, thanks for all the good work guys. |
Beta Was this translation helpful? Give feedback.
-
Why was The solution by kimgiutae is working, but is pretty verbose especially if there are a lot of different animations animating different properties beyond |
Beta Was this translation helpful? Give feedback.
You can use the fallbackStyle property of the Framer Motion animate component to specify styles that will be applied to the component if JavaScript is disabled. These styles will be applied directly to the element, so the animation will not run, but the element will still be visible on the page. Here is an example of how to use the fallbackStyle property:
You can also use the initial property to s…