我希望将变换原点更改为捏合手势的中心点。
这段工作代码(safariDevSample)应用缩放和旋转,而不更改transform-origin
:
window.angle = 0; //global to store data for later reset ....
var newAngle;
window.scale = 1;
var newScale;
function saveChanges() {
window.angle = newAngle;
window.scale = newScale;
}
function getAngleAndScale(e) {
// Don't zoom or rotate the whole screen
e.preventDefault();
newAngle = window.angle + e.rotation;
newScale = window.scale * e.scale;
if (newScale < 1) newScale = 1; //prepend to scale smaller then parent
// Combine scale and rotation into a single transform
var tString = "rotate(" + newAngle + "deg) scale(" + newScale + ")";
document.getElementById("theImg").style.webkitTransform = tString;
}
function init() {
document.getElementById("theImg").addEventListener("gesturechange", getAngleAndScale, false);
document.getElementById("theImg").addEventListener("gestureend", saveChanges, false);
}
init();
我尝试使用touchstart
和gesturestart screenX screenY
作为额外的事件监听器,但没有成功。