fix: 修复 imageGallery 开启 showToolbar 功能后导致页面不可滚动的问题 (#6108)

This commit is contained in:
liaoxuezhi 2023-01-31 10:53:50 +08:00 committed by GitHub
parent ba4d1ecc04
commit 000d05aa56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 9 deletions

View File

@ -134,6 +134,7 @@ export default {
title: '233', title: '233',
imageCaption: 'jfe fjkda fejfkda fejk fdajf dajfe jfkda', imageCaption: 'jfe fjkda fejfkda fejk fdajf dajfe jfkda',
enlargeAble: true, enlargeAble: true,
showToolbar: true,
originalSrc: '${image}' originalSrc: '${image}'
}, },
@ -144,6 +145,7 @@ export default {
thumbMode: 'cover', thumbMode: 'cover',
thumbRatio: '4:3', thumbRatio: '4:3',
enlargeAble: true, enlargeAble: true,
showToolbar: true,
originalSrc: '${src}' // originalSrc: '${src}' //
}, },

View File

@ -90,16 +90,21 @@ export class ImageGallery extends React.Component<
actions: ImageGallery.defaultProps.actions actions: ImageGallery.defaultProps.actions
}; };
componentDidMount() { galleryMain?: HTMLDivElement;
window.addEventListener('wheel', this.onWheelScroll.bind(this), { @autobind
passive: false galleryMainRef(ref: HTMLDivElement) {
}); if (ref) {
} ref.addEventListener('wheel', this.onWheelScroll, {
passive: false
componentWillUnmount() { });
window.removeEventListener('wheel', this.onWheelScroll); } else {
this.galleryMain?.removeEventListener('wheel', this.onWheelScroll);
}
this.galleryMain = ref;
} }
@autobind
onWheelScroll(event: WheelEvent) { onWheelScroll(event: WheelEvent) {
const showToolbar = this.state?.showToolbar; const showToolbar = this.state?.showToolbar;
@ -290,7 +295,10 @@ export class ImageGallery extends React.Component<
<div className={cx('ImageGallery-title')}> <div className={cx('ImageGallery-title')}>
{items[index].title} {items[index].title}
</div> </div>
<div className={cx('ImageGallery-main')}> <div
className={cx('ImageGallery-main')}
ref={this.galleryMainRef}
>
<img <img
src={items[index].originalSrc} src={items[index].originalSrc}
style={{transform: `scale(${scale}) rotate(${rotate}deg)`}} style={{transform: `scale(${scale}) rotate(${rotate}deg)`}}