Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I managed to get it working. </p> <p><a href="https://jsfiddle.net/NKyTZ/553/" rel="nofollow noreferrer">jsFiddle demo</a></p> <p>In the jsFiddle demo, clicking on the image represents a pinch gesture centred at the click point. Subsequent clicks increase the scale factor by a constant amount. To make this useful, you would want to make the scale and translate computations much more often on a transform event (hammer.js provides one).</p> <p>The key to getting it to work was to correctly compute the point of scale coordinates relative to the image. I used <code>event.clientX/Y</code> to get the screen coordinates. The following lines convert from screen to image coordinates:</p> <pre><code>x -= offset.left + newX y -= offset.top + newY </code></pre> <p>Then we compute a new size for the image and find the distances to translate by. The translation equation is taken from <a href="http://www.yuiblog.com/blog/2012/02/23/video-stephen-woods-html5-touch" rel="nofollow noreferrer">Stephen Woods' talk</a>.</p> <pre><code>newWidth = image.width() * scale newHeight = image.height() * scale newX += -x * (newWidth - image.width) / newWidth newY += -y * (newHeight - image.height) / newHeight </code></pre> <p>Finally, we scale and translate</p> <pre><code>image.css '-webkit-transform', "scale3d(#{scale}, #{scale}, 1)" wrap.css '-webkit-transform', "translate3d(#{newX}px, #{newY}px, 0)" </code></pre> <p>We do all our translations on a wrapper element to ensure that the translate-origin stays at the top left of our image.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload