Reactjs React-Spring和样式化组件
我是一个新的反应,试图整合一些动画。我正在使用Gatsby.js框架Reactjs React-Spring和样式化组件,reactjs,gatsby,react-spring,Reactjs,Gatsby,React Spring,我是一个新的反应,试图整合一些动画。我正在使用Gatsby.js框架 const LeadHeading = styled(animated.h1)` font-weight: bold; font-size: 3rem; font-family: ${props => props.theme.fontSecondary}; margin-bottom: 0; line-height: 2.5rem; color: #FFF3D8; const IndexPa
const LeadHeading = styled(animated.h1)`
font-weight: bold;
font-size: 3rem;
font-family: ${props => props.theme.fontSecondary};
margin-bottom: 0;
line-height: 2.5rem;
color: #FFF3D8;
const IndexPage = ({menuOpen}) => {
const h1Animation = useSpring({
opacity: menuOpen ? '0' : '1'
})
return (
<>
<Layout>
<Section className="hero is-fullheight">
<div className="hero-body container is-flex">
<LeadHeading
style={h1Animation}
>
some heading
</LeadHeading>
</div>
</Section>
</Layout>
</>
)
}
export default IndexPage
基本上,我只想在菜单弹出时淡出h1,因为菜单的透明度不好
感谢您的帮助。const LeadHeading=styled(animated.h1)`
const LeadHeading = styled(animated.h1)`
font-weight: bold;
font-size: 3rem;
font-family: ${props => props.theme.fontSecondary};
margin-bottom: 0;
line-height: 2.5rem;
color: #FFF3D8;
`
const IndexPage = ({menuOpen}) => {
const h1Animation = useSpring({
opacity: menuOpen ? '0' : '1'
})
return (
<>
<Layout>
<Section className="hero is-fullheight">
<div className="hero-body container is-flex">
<LeadHeading
style={h1Animation}
>
some heading....
</LeadHeading>
</div>
</Section>
</Layout>
</>
)
}
export default IndexPage
字体大小:粗体;
字体大小:3rem;
字体系列:${props=>props.theme.fontSecondary};
页边距底部:0;
线高:2.5雷姆;
颜色:#FFF3D8;
`
常量索引扩展=({menuOpen})=>{
常量h1Animation=useSpring({
不透明度:菜单栏“0”:“1”
})
返回(
一些标题。。。。
)
}
导出默认索引扩展
编辑//菜单状态通过useState钩子在“布局”组件中进行管理。
但是,将数据传递给“IndexPage”应该是可能的,对吗
好的,我想我可以跳过render方法中的动画部分,因为我在上面的styled component变量中使用了它。(我在上一篇文章中忘了提到这一点)。
你的方法是我最初的方法之一,但它不起作用。没有“道具”,你分解了“菜单打开”。当然,是的,我重写了一些代码。但它仍然不起作用。Sry我不能编辑问题,它也应该这样工作。但是如果不使用plain animated.h1,它是否可以工作?如果这不起作用,那么问题就出在代码或配置的其他地方。我正在使用盖茨比框架。有一个名为“盖茨比布局插件”的插件,它支持在“布局”和“页面”之间传递数据。
const LeadHeading = styled(animated.h1)`
font-weight: bold;
font-size: 3rem;
font-family: ${props => props.theme.fontSecondary};
margin-bottom: 0;
line-height: 2.5rem;
color: #FFF3D8;
`
const IndexPage = ({menuOpen}) => {
const h1Animation = useSpring({
opacity: menuOpen ? '0' : '1'
})
return (
<>
<Layout>
<Section className="hero is-fullheight">
<div className="hero-body container is-flex">
<LeadHeading
style={h1Animation}
>
some heading....
</LeadHeading>
</div>
</Section>
</Layout>
</>
)
}
export default IndexPage