javascript - 当组件离开页面时反应整个页面滚动条
问题描述
我有一个这样的应用程序:
正如您所看到的,中间组件继续向下超出页面,这就是为什么我需要一个滚动条来向下滚动到它。但是如果我直接将它附加在中间组件上,我只能让它工作,但我想要一个常规的整页滚动条。
这是我的 app.js
import React, { Component } from 'react';
import OysterView from './components/OysterView.js'
import './uikit/uikit.css';
import './App.css';
import logo from './uikit/assets/images/hrm-white.svg';
class App extends Component {
render() {
return (
<div className="App">
<div className="App-header">
<header>
<img src={logo} className="App-logo" alt="HRM"/>
</header>
</div>
<div className="OysterView">
<OysterView />
</div>
</div>
);
}
}
export default App;
我尝试将其设置在不同的位置,但它无法识别组件超出范围,因此无法向下滚动组件是超出范围<OysterView />
的组件,因此我在 CSS 中尝试过
.App {
overflow-y: scroll;
background-color: #fafafa;
position: fixed;
height: 100vh;
width: 100vw;
z-index: -2
}
也试过这个:
html{
height: 100%;
overflow-y: scroll;
margin: 0;
padding: 0;
}
这根本没有添加任何东西,这可能是因为 .App 没有高度,但是如果我添加高度,其余的内容就会被向下推,所以它什么也解决不了。我也尝试将它添加到 index.css html 中,这给了我一个滚动条,但它不能向下滚动。所以我在这里没有想法。我应该如何攻击这个?.App 上的 z-index?
解决方案
您必须滚动组件本身,只需使其容器全屏,以便滚动条位于窗口的右侧。
.modal-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba( 0, 0, 0, .5 );
overflow-y: scroll;
}
.modal-content {
background: red;
margin: 20%;
height: 2000px;
}
Page content
<div class="modal-container">
<div class="modal-content">
Modal content
</div>
</div>
推荐阅读
- google-cloud-firestore - Firestore 规则为什么这不起作用?
- android - 如何为 Android 活动获取半透明背景?
- vba - 将粘贴数据复制到文件夹中的多个工作簿中
- xslt - 使用 Apache FOP 2.3 的空 xsl 会导致 eclipse
- swift - Mac OS:直接从 Swift 中的目录访问内容
- javascript - 在 Service Worker 中缓存跨域资产
- spring-boot - 未找到 H2 数据库
- angular - 我想通过路由将数组对象作为参数传递给另一个页面我的功能如下
- c++ - 从“catch all”块中重新抛出异常如何在 C++ 中生成相同的异常?
- angular - 获取 ngFor 项目的索引并更新值