【发布时间】:2017-03-14 14:13:18
【问题描述】:
我正在使用 reactjs 做一个 Web 应用程序。我需要在向下滚动时更改 div 的高度,并在向上滚动时恢复到原始高度。我不确定是否有我需要的纯 CSS 解决方案。实现我上面描述的方法是什么。
class InternalGroupsPage extends Component {
constructor() {
super();
}
render() {
return (
<div className="body_clr">
<div className="group_page_header">
This is the div i want to change the height when scrolling
</div>
<div>
Other stuff
</div>
</div>
);
}
}
CSS
.group_page_header {
width: 100%;
height: 220px;
background-color: #0b97c4;
position: fixed;
margin-top: 50px;
z-index: 1;
}
.body_clr {
overflow-y: scroll;
width: 100%;
height: 100%;
position: fixed;
background-color: #eceff1;
}
【问题讨论】:
-
你的 react 组件代码在哪里?
-
我只给出了html和css,因为我认为不需要其他代码。无论如何我现在已经更新了
-
如果你能给我一个小提琴上面的代码工作,我可以为你做。基本上,当
scrollTop通过某个点以进行重新渲染时,您需要切换状态变量 + className。有意义吗?
标签: javascript html css reactjs