gpt4 book ai didi

css - 滚动不工作 : react-grid-layout: 0-showcase example

转载 作者:行者123 更新时间:2023-12-04 17:53:27 27 4
gpt4 key购买 nike

我正在尝试复制 0-showcase react-grid-layout 的示例,一切正常,除了包含网格及其组件的主要 HTML 元素不可滚动。我试过将 overflow-y scroll 提供给正文和后续元素,但无济于事。我正在使用 Gastsby 静态站点生成器来加速开发。因此,在我的 pages 中,直接在 Gastby 文件夹结构中,我创建了一个 grid.js 文件,其中包含以下 react 代码。几乎所有内容都在 example code here 中定义.这可能是我没有得到的一个小的 CSS 修复,但我真的不明白我在这里缺少什么。提前致谢!

import React, {PropTypes} from 'react'
import {Responsive, WidthProvider} from 'react-grid-layout';
import lomap from 'lodash.map'
import loresult from 'lodash.result'
import lorange from 'lodash.range'
import lorandom from 'lodash.random'

import "../node_modules/react-grid-layout/css/styles.css"
import "../node_modules/react-resizable/css/styles.css"

const ResponsiveReactGridLayout = WidthProvider(Responsive)

// const originalLayouts = getFromLS('layouts') || {}

function generateLayout() {
return lomap( lorange(0, 25), function (item, i) {
var y = Math.ceil(Math.random() * 4) + 1;
return {
x: lorandom(0, 5) * 2 % 12,
y: Math.floor(i / 6) * y,
w: 2,
h: y,
i: i.toString(),
static: Math.random() < 0.05
};
});
}

export default class MyLayout extends React.Component {

// static propTypes = {
// onLayoutChange: PropTypes.func.isRequired
// }

static defaultProps = {
className: "layout",
rowHeight: 30,
cols: {lg: 12, md: 10, sm: 6, xs: 4, xxs: 2},
initialLayout: generateLayout()
}

state = {
currentBreakPoint: 'lg',
mounted: false,
layouts: {lg: this.props.initialLayout}
}

constructor(props, context){
super(props, context)
}

componentDidMount() {
this.setState({
mounted: true
})
}

generateDOM() {

const styles = {
background: "#eee"
}

return lomap(this.state.layouts.lg, (l, i) => {
return (
<div style={styles} key={i} className={l.static ? 'static': ''}>
{
l.static ?
<span className="text" title="This item is static and can't be removed or resized">
static - {i}
</span> :
<span className="text">{i}</span>
}
</div>
)
})
}

onBreakPointChange(breakpoint) {
this.setState({
currentBreakPoint: breakpoint
})
}

onLayoutChange(layout, layouts) {
// this.props.onLayoutChange(layout, layouts)
console.log(layout, layouts);
}

onNewLayout() {
this.setState({
layouts: {
lg: generateLayout()
}
})
}

render() {
return (
<div>
<div>Current Breakpoint: {this.state.currentBreakpoint} ({this.props.cols[this.state.currentBreakpoint]} columns)
</div>
<button onClick={this.onNewLayout}>Generate New Layout</button>
<ResponsiveReactGridLayout
{...this.props}
layouts={this.state.layouts}
onBreakpointChange={this.onBreakpointChange}
onLayoutChange={this.onLayoutChange}
// WidthProvider option
measureBeforeMount={false}
// I like to have it animate on mount. If you don't, delete `useCSSTransforms` (it's default `true`)
// and set `measureBeforeMount={true}`.
useCSSTransforms={this.state.mounted}>
{this.generateDOM()}
</ResponsiveReactGridLayout>
</div>
)
}
}

最佳答案

这是一个非常愚蠢的问题。我只是不得不做

body {
overflow: auto
}

并为我的 react-grid-layout 组件提供高度

render() {
const styles = {
height: "100vh" // just this!
}
return (
<div>
<div>Current Breakpoint: {this.state.currentBreakpoint} ({this.props.cols[this.state.currentBreakpoint]} columns)
</div>
<button onClick={this.onNewLayout}>Generate New Layout</button>
<ResponsiveReactGridLayout
style={styles} // AND THIS!
{...this.props}
layouts={this.state.layouts}
onBreakpointChange={this.onBreakpointChange}
onLayoutChange={this.onLayoutChange}
// WidthProvider option
measureBeforeMount={false}
// I like to have it animate on mount. If you don't, delete `useCSSTransforms` (it's default `true`)
// and set `measureBeforeMount={true}`.
useCSSTransforms={this.state.mounted}>
{this.generateDOM()}
</ResponsiveReactGridLayout>
</div>
)
}

关于css - 滚动不工作 : react-grid-layout: 0-showcase example,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42423662/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com