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',
imageCaption: 'jfe fjkda fejfkda fejk fdajf dajfe jfkda',
enlargeAble: true,
showToolbar: true,
originalSrc: '${image}'
},
@ -144,6 +145,7 @@ export default {
thumbMode: 'cover',
thumbRatio: '4:3',
enlargeAble: true,
showToolbar: true,
originalSrc: '${src}' //
},

View File

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