如何在使用Reactjs材质UI滚动时自动隐藏AppBar
如何自动隐藏我的Reactjs如何在使用Reactjs材质UI滚动时自动隐藏AppBar,reactjs,scroll,material-design,material-ui,Reactjs,Scroll,Material Design,Material Ui,如何自动隐藏我的Reactjs MyAppBar.js 从“React”导入React; 从“道具类型”导入道具类型; 从“@material ui/core/styles”导入{withStyles}”; 从“@material ui/core/AppBar”导入AppBar; 从“@material ui/core/Toolbar”导入工具栏; 从“@material ui/core/Typography”导入排版; 从“@material ui/core/Button”导入按钮; 从“@
MyAppBar.js
从“React”导入React;
从“道具类型”导入道具类型;
从“@material ui/core/styles”导入{withStyles}”;
从“@material ui/core/AppBar”导入AppBar;
从“@material ui/core/Toolbar”导入工具栏;
从“@material ui/core/Typography”导入排版;
从“@material ui/core/Button”导入按钮;
从“@material ui/core/IconButton”导入IconButton;
从“@material ui/icons/Menu”导入菜单图标;
常量样式={
根目录:{
flexGrow:1,
},
成长:{
flexGrow:1,
},
菜单按钮:{
边缘左:-12,
marginRight:20,
},
};
功能按钮工具栏(道具){
常量{classes}=props;
返回(
新闻
登录
);
}
ButtonAppBar.propTypes={
类:PropTypes.object.isRequired,
};
导出默认样式(样式)(按钮栏);
您可以与
这里的要点是,useCrollTrigger
在向下滚动时(默认情况下)将返回true
,当窗口垂直滚动条位置达到某个阈值时(默认情况下距原点100
像素)-在向上滚动时返回false
。因此,这些就是我们在幻灯片
prop的中否定它的原因
export default function HideAppBar() {
const trigger = useScrollTrigger();
return (
<>
<Slide appear={false} direction="down" in={!trigger}>
<AppBar>
<Toolbar>
<Typography variant="h6">Scroll Down to Hide App Bar</Typography>
</Toolbar>
</AppBar>
</Slide>
...
</>
);
}
导出默认函数hideapbar(){
const trigger=useCollTrigger();
返回(
您可以使用我在回答顶部提供的与useCollTrigger
相关的链接自定义选项,如threshold
参考资料:可能的副本
export default function HideAppBar() {
const trigger = useScrollTrigger();
return (
<>
<Slide appear={false} direction="down" in={!trigger}>
<AppBar>
<Toolbar>
<Typography variant="h6">Scroll Down to Hide App Bar</Typography>
</Toolbar>
</AppBar>
</Slide>
...
</>
);
}