I'm building a web app using nextjs 13 with the app directory. I want the pages to have cool page transitions and items smoothly appearing as you scroll and so forth using mostly gsap animation.
我正在使用带有app目录的nextjs 13构建一个Web应用程序。我希望页面有很酷的页面过渡和项目平滑地出现,因为你滚动等主要使用gsap动画。
My question is, can I use server components for all the components and then just sprinkle that animation stuff on top somehow (using refs or something, I don't know) or would this require me to use the 'use client' directive for all components that will have this type of animation?
我的问题是,我可以为所有组件使用服务器组件,然后以某种方式将动画内容洒在上面(使用Ref或其他什么,我不知道),或者这是否要求我对所有将具有这种类型动画的组件使用‘Use Client’指令?
My big issue is thinking in a PHP way where you'd use JavaScript on the client to do things like getElementById()
and add interactivity that way.
我最大的问题是以一种PHP的方式思考,您将在客户机上使用JavaScript来做像getElementById()这样的事情,并以这种方式添加交互性。
I want to understand how to use server components in this way where you'd want the component data on the server but also have that component have some interactive animation. Any pointers in the right direction would be massively helpful here. thanks.
我想了解如何以这种方式使用服务器组件,在这种情况下,您需要服务器上的组件数据,同时该组件还具有一些交互动画。在这里,任何正确方向的指示都会有很大帮助。谢谢。
更多回答
Hello. I am currently on the same task. I found this video, maybe this will help you. youtube.com/watch?app=desktop&v=ugCN_gynFYw Animations usually applied on the client side. You can load the server component, but you need CSS and other client-side libs to animate transitions. Also, please read the "formatting your questions" guide, because it's inconvenient to read your question. No paragraphs, no code formatting.
你好。我目前也在做同样的工作。我找到了这段视频,也许这会对你有所帮助。Youtube.com/watch?app=Desktop&v=ugCN_gynFYw动画通常应用于客户端。您可以加载服务器组件,但您需要使用css和其他客户端库来为转换设置动画。另外,请阅读“格式化您的问题”指南,因为它不方便阅读您的问题。没有段落,没有代码格式。
Thanks, Victor, and sorry for the poorly formatted question. I'll run through the YouTube video and hopefully get clarification on some things.
谢谢你,维克多,对不起,格式不好的问题。我会浏览一下YouTube视频,希望能澄清一些事情。
yeah, now the question is much better
是啊,现在问题好多了
👍awesome, thanks again!
👍太棒了,再次感谢!
我是一名优秀的程序员,十分优秀!