javascript - 滚动时反应网格库延迟加载
问题描述
我正在使用 React 网格库(https://github.com/benhowell/react-grid-gallery)来显示图像,但我不能作为页面上的滚动用户延迟加载。
<Gallery
images={this.props.newExamples}
enableImageSelection
thumbnailImageComponent={ImageComponent}
rowHeight={this.props.newExamples[0].thumbnailHeight}
margin={10}
onSelectImage={(index, image) => this.onSelectImageNewExample(index, image)}
/>
解决方案
我在 thumbnailImageComponent 中使用了 react-lazy-load-image-component ,如下所示:
class ImageComponent extends React.Component {
constructor(props) {
super(props);
}
render () {
console.log(this.props.imageProps)
return (
<LazyLoadImage
height={this.props.imageProps.style.width}
width={this.props.imageProps.style.width}
src={this.props.imageProps.src}
/>
);
}
}
使用ANimator120的功能组件进行编辑:
const ImageComponent = (props) => {
const { imageProps } = props;
return (
<LazyLoadImage
height={imageProps.style.width}
width={imageProps.style.width}
src={imageProps.src}
/>
);
};
推荐阅读
- c++ - 如何用 C++ 编写映射程序
- c# - 使用 2 个嵌套形式,但内部形式未在 asp.net 中显示
- blockchain - 如何在 Solana 上与其他人的公共程序互动?
- c# - 单击按钮后禁用使用 CSSclass 的 asp.net C# gridview 样式
- if-statement - 将数据从多列转换为行并保留“标签”
- javascript - 在 Angular 11 中获取 http://localhost:4200/account/runtime.js net::ERR_ABORTED 404(未找到)
- python - 尝试使用开源库为我的数据集预测性别,但仅在预测性别中显示男性
- reactjs - react.js 重新渲染组件仅在为 state 赋予另一个值时才起作用,与以前不同
- reactjs - React Financial Chart 未显示图表并抛出错误 - 在严格模式树中检测到旧版上下文 API
- docker - Docker 容器无法使用容器名称访问另一个容器