Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript zoom and rotate using gesturechange and gestureend
    primarykey
    data
    text
    <p>I am working on some touch events and gestures, I want to be able to zoom and rotate the object, I have successfully made it draggable but the gestures are giving me trouble. The gestures are working but they are choppy, whenever you pinch it to zoom in or zoom out or try to rotate it, it jumps from finger to finger. </p> <p>Here is my code for reference. </p> <pre><code>var width = 300; var height = 300; var rotation = 0; $('.dynamic').live("gesturechange gestureend", function(e){ var orig = e.originalEvent; if(e.type == 'gesturechange'){ e.preventDefault(); $(this).css("width", parseFloat(width) * orig.scale); $(this).css("height", parseFloat(height) * orig.scale); $(this).css("-webkit-transform","rotate(" + ((parseFloat(rotation) + orig.rotation) % 360) + "deg)"); }else if(e.type == 'gestureend'){ a.w[ids] = parseFloat(width) * orig.scale; a.h[ids] = parseFloat(height) * orig.scale; a.rotation[ids] = (parseFloat(rotation) + orig.rotation) % 360; } }); </code></pre> <p>Are there anyways to make this smooth, and prevent it from jumping from fingers, or is the approach I took wrong. In need of some tips and tricks and help</p> <p>found a solution </p> <p>Seems like the my touch event for drag interfered with the gestures thats why it kept jumping from finger to finger, the way around this was to not use gestures instead count the touches on the object and use touch start,end and change instead.</p> <p>Here is the code</p> <pre><code>var touches = 0; var width = 300; var height = 300; var rotation = 0; $('.dynamic').live("touchstart touchmove touchend", function(e){ var orig = e.originalEvent; if(e.type == 'touchstart'){ if(orig.touches.length == 1){ touches = 1; }else if(orig.touches.length == 2){ touches = 2; } }else if(e.type == 'touchmove'){ e.preventDefault(); if(touches == 2){ $(this).css("width", parseFloat(width) * orig.scale); $(this).css("height", parseFloat(height) * orig.scale); $(this).css("-webkit-transform","rotate(" + ((parseFloat(rotation) + orig.rotation) % 360) + "deg)"); } }else if(e.type == 'touchend'){ if(touches == 2){ a.w[ids] = parseFloat(width) * orig.scale; a.h[ids] = parseFloat(height) * orig.scale; a.rotation[ids] = (parseFloat(rotation) + orig.rotation) % 360; } } }); </code></pre>
    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.
 

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