Skip to content

Commit 40a0a76

Browse files
committed
Refactor touch event handling in Hero component to improve rotation logic
- Removed unused variable `lastTouchX`. - Updated touch event handlers to calculate normalized positions for X and Y rotations. - Enhanced rotation behavior to include Z-axis adjustments, aligning with hover interactions.
1 parent 78e1c74 commit 40a0a76

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/components/hero/index.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ void main() {
144144
let currentRotationY = 0;
145145
let currentRotationZ = 0;
146146
let isDragging = false;
147-
let lastTouchX = 0;
148147

149148
function onMouseMove(e: MouseEvent) {
150149
const x = (e.clientX / window.innerWidth) * 2 - 1;
@@ -157,7 +156,6 @@ void main() {
157156

158157
function onTouchStart(e: TouchEvent) {
159158
isDragging = true;
160-
lastTouchX = e.touches[0].clientX;
161159
// Prevent default touch behavior
162160
e.preventDefault();
163161
}
@@ -169,17 +167,14 @@ void main() {
169167
e.preventDefault();
170168

171169
const touchX = e.touches[0].clientX;
170+
const touchY = e.touches[0].clientY;
172171

173-
const deltaX = (touchX - lastTouchX) / window.innerWidth;
172+
const x = (touchX / window.innerWidth) * 2 - 1;
173+
const y = (touchY / window.innerHeight) * 2 - 1;
174174

175-
// Only update Y rotation (left/right movement)
176-
targetRotationY += deltaX * MAX_TILT * 2;
177-
targetRotationY = Math.max(
178-
-MAX_TILT,
179-
Math.min(MAX_TILT, targetRotationY)
180-
);
181-
182-
lastTouchX = touchX;
175+
targetRotationX = y * MAX_TILT;
176+
targetRotationY = x * MAX_TILT;
177+
targetRotationZ = -y * MAX_TILT;
183178
}
184179

185180
function onTouchEnd() {

0 commit comments

Comments
 (0)