JavaScript Using Hammerjs for pinch and zoom on image pinch zoom using hammer.js,hammer.js pinch zoom,pinch

So I have a header.. and an image. On tablet I want to be able to pinch and zoom into the image but i'm struggling. I've looked at other similar questions. But as I'm still learning, i'm not fully sure what is going wrong for me too fix.

<div class="header">
      <h1><img src="logo.png" alt="">Title</h1>
      <ul>
        <li>Test</li>
        <li>Test</li>
        <li>Test</li>
      </ul>
    </div>


    <div id="map">
      <div>
        <img src="bg.png" alt="" width="1200" id="mapImage">
      </div>
    </div>

    <script src="https://hammerjs.github.io/dist/hammer.js"></script>

Below is my Javascript i'm using to try and get the pinch and zoom working correctly. I'm using hammer.js for this.

<script>
  var hammertime = Hammer(document.getElementById('map'), {
    transform_always_block: true,
    transform_min_scale: 1,
    drag_block_horizontal: false,
    drag_block_vertical: false,
    drag_min_distance: 0
  });

  var rect = document.getElementById('mapImage');

  var posX=0, posY=0,
      scale=1, last_scale,
      last_posX=0, last_posY=0;

  hammertime.on('touch drag transform dragend', function(ev) {
    console.log(ev);
      switch(ev.type) {
          case 'touch':
              last_scale = scale;
              break;

          case 'drag':
              posX = last_posX + ev.gesture.deltaX;
              posY = last_posY + ev.gesture.deltaY;
              break;

          case 'transform':
              scale = Math.max(1, Math.min(last_scale * ev.gesture.scale, 10));
              break;
          case 'dragend':
              last_posX = posX;
              last_posY = posY;
              break;
      }

      // transform!
      var transform = "";
      if(scale > 1){
          transform =
              "translate3d("+posX+"px,"+posY+"px, 0) " +
              "scale3d("+scale+","+scale+", 0) ";
      }else{
          transform =
              "translate3d(0, 0, 0) " +
              "scale3d(1, 1, 0) ";
          posX = 0;
          posY = 0;
          last_posX = 0;
          last_posY = 0;
      }

      rect.style.transform = transform;
      rect.style.oTransform = transform;
      rect.style.msTransform = transform;
      rect.style.mozTransform = transform;
      rect.style.webkitTransform = transform;
  });
</script>

Thanks for help!

Answer:1

Let's say I have something like this: <div ng-app="myApp"> <div ng-controller="myCtrl"> {{foo}} <button ng-click="bindToMe" /> </div> <div ng-...

Let's say I have something like this: <div ng-app="myApp"> <div ng-controller="myCtrl"> {{foo}} <button ng-click="bindToMe" /> </div> <div ng-...

  1. programmatically bind combobox c#
  2. programmatically bind datagridview c#
  3. programmatically bind visibility
  4. wpf programmatically bind property
  5. wpf programmatically bind dependency property
  6. objectdatasource programmatically bind
  7. wpf programmatically bind
  8. bind gridview column programmatically c#
  9. vue bind programmatically
  10. angular bind programmatically
  11. knockout data-bind programmatically
  12. wpf datagrid bind programmatically
  13. nsarraycontroller bind programmatically
  14. v-bind programmatically
  15. c# bind programmatically
  16. cocoa bind programmatically

I'm Very stuck in this case when working all day :(. please help me. I have website need using $http provider to call ColdFusion file from other domain. let's say this is link to cfm file : http://...

I'm Very stuck in this case when working all day :(. please help me. I have website need using $http provider to call ColdFusion file from other domain. let's say this is link to cfm file : http://...

How to break sequence of handlers of Promises/A? For example if we have sequence: method1().then(method2()) .then(method3(), errorHandler3()); and in method2() we decided to break ...

How to break sequence of handlers of Promises/A? For example if we have sequence: method1().then(method2()) .then(method3(), errorHandler3()); and in method2() we decided to break ...

I am working with file-picker. from front-end side user is filling a form and uploading files in it, which are stored using file-picker. on submit of users form I have to send him acknowledgement ...

I am working with file-picker. from front-end side user is filling a form and uploading files in it, which are stored using file-picker. on submit of users form I have to send him acknowledgement ...