Browse Source

fix: 冒泡

wumu 4 years ago
parent
commit
ea7a3dbdf6
2 changed files with 7 additions and 0 deletions
  1. 6 0
      src/PhotoSlider.tsx
  2. 1 0
      src/PhotoView.tsx

+ 6 - 0
src/PhotoSlider.tsx

@@ -97,6 +97,7 @@ export default class PhotoSlider extends React.Component<IPhotoSliderProps, Phot
       photoIndex: index,
     });
     window.addEventListener('keydown', this.handleKeyDown);
+    window.addEventListener('popstate', this.handleBack);
   }
 
   componentWillUnmount() {
@@ -169,6 +170,11 @@ export default class PhotoSlider extends React.Component<IPhotoSliderProps, Phot
     }
   };
 
+  handleBack = (evt: KeyboardEvent) => {
+    evt.stopPropagation();
+    console.log("范湖一")
+  };
+
   handleReachVerticalMove = (clientY, scale) => {
     this.setState(({ lastClientY, backdropOpacity }) => {
       if (lastClientY === undefined) {

+ 1 - 0
src/PhotoView.tsx

@@ -306,6 +306,7 @@ export default class PhotoView extends React.Component<IPhotoViewProps, typeof i
   };
 
   handleWheel = e => {
+    e.stopPropagation();
     const { clientX, clientY, deltaY } = e;
     const { width, naturalWidth, reachState } = this.state;
     if (reachState !== ReachTypeEnum.Normal) {