javascript - React-Spring 根据媒体查询改变视差偏移
问题描述
我在网页上使用 React Spring for Parallax,但是页面上较高的组件之一<Section2 />
使用 flexbox 强制 4 个大的水平图标在较小的屏幕上呈现为 2 x 2 图标。
<Section3>
发生这种情况时,它会导致移动视图中的偏移值错误。所以我的问题是如何通过媒体查询或其他方式更改偏移值。
这是我的代码:
const Home = () => {
return (
<>
<Layout>
<SEO title="Home" />
<Parallax pages={4}>
<ParallaxLayer offset={0} speed={1} style={{ zIndex: '5' }}>
<Hero />
</ParallaxLayer>
<ParallaxLayer offset={0.7} speed={1.4} style={{ zIndex: '10' }}>
<HeroName />
</ParallaxLayer>
<ParallaxLayer
offset={0.8}
speed={0.7}
style={{ zIndex: '-1', backgroundColor: '#fcf7f0' }}
>
<Section1 />
</ParallaxLayer>
<ParallaxLayer offset={1} speed={0.8} style={{ zIndex: '3' }}>
<Section2 />
</ParallaxLayer>
<ParallaxLayer offset={1.2} speed={0.5} >
<Section3 />
</ParallaxLayer>
</Parallax>
</Layout>
</>
);
};
非常感谢
解决方案
我通过使用三元解决了这个问题。
offset={window.innerWidth < 768 ? 2.1 : 1.2}
推荐阅读
- python - 批量更新不更新 PyMongo 中的值
- python - 我尝试使用 PIL 放置像素(RGB 像素),但总是失败
- kotlin - 映射转换以在作为 url 的字符串列表上应用新路径
- android - 传感器的本机模块不可用。react-native 链接是否运行成功?
- css - 表格内的按钮元素显示在 div 元素中的文本上方
- java - 在 Java 中总是四舍五入到十
- oop - 参数对象的构建器模式
- c++ - 如何在 Xcode 上为 C++ 安装 vinecopulib 库?
- python - 关于图像大小,使用opencv python对图像进行网格化
- isabelle - 如何证明相互递归类型的引理?