Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pan, Can't scroll down, it's stuck #1291

Open
cubarabara opened this issue Sep 22, 2023 · 1 comment
Open

Pan, Can't scroll down, it's stuck #1291

cubarabara opened this issue Sep 22, 2023 · 1 comment

Comments

@cubarabara
Copy link

cubarabara commented Sep 22, 2023

I have a problem, when zoomed in it can't be scrolled down

On mobile

Video.mp4
<html>

<head>
   <title>Document</title>
   <script src='https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.js'></script>
   <style type="text/css" media="all">
      * {
         margin: 0;
         padding: 0;
      }
      
      .container {
         display: flex;
         width: 100%;
         height: 100%;
         align-items: center;
         justify-content: center;
         background: pink;
         position: absolute;
         overflow: hidden;
      }
      
      .wrapper {
         display: flex;
         position: absolute;
         width: 100%;
         height: 100%;
         background: blue;
         cursor: move;
         touch-action: none;
      }
      
      .test {
         width: 300px;
         height: 300px;
         background: red;
         position: absolute;
      }
      
   </style>
</head>

<body>
   <div class="container">
      <div class="wrapper">
         <div class="test">
            p
         </div>
      </div>
   </div>
   
   <script>
      var zoomPanDiv = document.querySelector(".wrapper");
      var hammer = new Hammer(zoomPanDiv);
      
      var scale = 1;
      var lastScale = 1;
      var posX = 0;
      var posY = 0;
      var lastPosX = 0;
      var lastPosY = 0;
   
      hammer.get('pinch').set({ enable: true });
      hammer.get('pan').set({ direction: Hammer.DIRECTION_ALL });

      hammer.on('pinch', (e) => {
         scale = Math.max(1, Math.min(lastScale * e.scale, 3));
         zoomPanDiv.style.transform = `scale(${scale}) translateX(${posX}px) translateY(${posY}px)`;
      });
   
      hammer.on('pinchend', function () {
         lastScale = scale;
      });
   
      hammer.on('pan', (e) => {
         posX = Math.max(-zoomPanDiv.clientWidth * (scale - 1), Math.min(0, lastPosX + e.deltaX));
         posY = Math.max(-zoomPanDiv.clientHeight * (scale - 1), Math.min(0, lastPosY + e.deltaY));
   
         zoomPanDiv.style.transform = `scale(${scale}) translateX(${posX}px) translateY(${posY}px)`;
         console.log(e)
      });
   
      hammer.on('panend', (e) => {
         lastPosX = posX;
         lastPosY = posY;
      });
   </script>
</body>

</html>
@cubarabara cubarabara changed the title Pan, Can't scroll down Pan, Can't scroll down, it's stuck Sep 22, 2023
@ovanderzee
Copy link

ovanderzee commented Apr 3, 2024

Happens in combination with swipe too, when trying to start the scroll on the target element. Outside the target element everything works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants