Код: Выделить всё
imageContainer.addEventListener("touchstart", function (event) {
event.preventDefault();
if (event.touches.length === 2) {
let touch1s = [event.touches[0].pageX, event.touches[0].pageY];
let touch2s = [event.touches[1].pageX, event.touches[1].pageY];
x = Math.abs(touch1s[0] + touch2s[0]) / 2;
y = Math.abs(touch1s[1] + touch2s[1]) / 2;
originalDistance = Math.hypot(event.touches[0].pageX - event.touches[1].pageX,event.touches[0].pageY - event.touches[1].pageY );
zoomDrag[0].disable();
}
});
Код: Выделить всё
imageContainer.addEventListener("touchmove", function (event) {
event.preventDefault();
if (event.touches.length === 2) {
let currentDistance = Math.hypot(event.touches[0].pageX - event.touches[1].pageX,event.touches[0].pageY - event.touches[1].pageY);
if (originalDistance < currentDistance) {
if (gsap.getProperty(imageContainer, "scale") currentDistance) {
if (gsap.getProperty(imageContainer, "scale") >= minScale) {
zoom_control(imageContainer, x, y, "-=0.4");
}
}
}
});
Математика — не моя сильная сторона, так какая формула будет правильной, чтобы начало преобразования было правильным?
Подробнее здесь: https://stackoverflow.com/questions/793 ... is-applied
Мобильная версия