Skip to content

Commit 69ad173

Browse files
committed
introduce cursor move
1 parent 7117214 commit 69ad173

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

src/js/index.js

+23-25
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,8 @@ export default function Tobii (userOptions) {
966966
const pointermoveHandler = (event) => {
967967
if (!pointerDownCache.length) return
968968

969+
groups[activeGroup].slider.classList.add('tobii__slider--is-' + (isZoomed() ? 'moving' : 'dragging'))
970+
969971
// Find this event in the cache and update its record with this event
970972
const index = pointerDownCache.findIndex(
971973
(cachedEv) => cachedEv.pointerId === event.pointerId
@@ -1012,8 +1014,6 @@ export default function Tobii (userOptions) {
10121014
// Skip animation if drag distance is too low
10131015
if (distance(deltaX, deltaY) < 10) return
10141016

1015-
groups[activeGroup].slider.classList.add('tobii__slider--is-dragging')
1016-
10171017
if (Math.abs(deltaX) > Math.abs(deltaY) && groups[activeGroup].elementsLength > 1) {
10181018
// Horizontal swipe
10191019
groups[activeGroup].slider.style.transform =
@@ -1033,14 +1033,33 @@ export default function Tobii (userOptions) {
10331033
const pointerupHandler = (event) => {
10341034
event.stopPropagation()
10351035

1036+
groups[activeGroup].slider.classList.remove('tobii__slider--is-' + (isZoomed() ? 'moving' : 'dragging'))
1037+
10361038
// Remove this event from the target's cache
10371039
const index = pointerDownCache.findIndex(
10381040
(cachedEv) => cachedEv.pointerId === event.pointerId
10391041
)
10401042
pointerDownCache.splice(index, 1)
10411043

1042-
const isDragging = DRAG.startX !== DRAG.x || DRAG.startY !== DRAG.y
1043-
if (!isDragging) {
1044+
const MOVEMENT_X = DRAG.startX - DRAG.x
1045+
const MOVEMENT_Y = DRAG.startY - DRAG.y
1046+
const MOVEMENT_X_DISTANCE = Math.abs(MOVEMENT_X)
1047+
const MOVEMENT_Y_DISTANCE = Math.abs(MOVEMENT_Y)
1048+
if (MOVEMENT_X_DISTANCE || MOVEMENT_Y_DISTANCE) {
1049+
if (!isZoomed()) {
1050+
// Evaluate drag
1051+
if (MOVEMENT_X < 0 && MOVEMENT_X_DISTANCE > userSettings.threshold && groups[activeGroup].currentIndex > 0) {
1052+
previous()
1053+
} else if (MOVEMENT_X > 0 && MOVEMENT_X_DISTANCE > userSettings.threshold &&
1054+
groups[activeGroup].currentIndex !== groups[activeGroup].elementsLength - 1) {
1055+
next()
1056+
} else if (MOVEMENT_Y > 0 && MOVEMENT_Y_DISTANCE > userSettings.threshold && userSettings.swipeClose) {
1057+
close()
1058+
} else {
1059+
updateOffset()
1060+
}
1061+
}
1062+
} else {
10441063
// Evaluate tap
10451064
const currentTime = new Date().getTime()
10461065
const tapLength = currentTime - lastTapTime
@@ -1069,27 +1088,6 @@ export default function Tobii (userOptions) {
10691088
}
10701089
}
10711090
}
1072-
1073-
if (isDragging && !isZoomed()) {
1074-
// Evaluate drag
1075-
groups[activeGroup].slider.classList.remove('tobii__slider--is-dragging')
1076-
1077-
const MOVEMENT_X = DRAG.startX - DRAG.x
1078-
const MOVEMENT_Y = DRAG.startY - DRAG.y
1079-
const MOVEMENT_X_DISTANCE = Math.abs(MOVEMENT_X)
1080-
const MOVEMENT_Y_DISTANCE = Math.abs(MOVEMENT_Y)
1081-
1082-
if (MOVEMENT_X < 0 && MOVEMENT_X_DISTANCE > userSettings.threshold && groups[activeGroup].currentIndex > 0) {
1083-
previous()
1084-
} else if (MOVEMENT_X > 0 && MOVEMENT_X_DISTANCE > userSettings.threshold &&
1085-
groups[activeGroup].currentIndex !== groups[activeGroup].elementsLength - 1) {
1086-
next()
1087-
} else if (MOVEMENT_Y > 0 && MOVEMENT_Y_DISTANCE > userSettings.threshold && userSettings.swipeClose) {
1088-
close()
1089-
} else {
1090-
updateOffset()
1091-
}
1092-
}
10931091
}
10941092

10951093
/**

src/scss/tobii.scss

+4-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@
122122
&--is-dragging [data-type] {
123123
cursor: grabbing;
124124
}
125+
126+
&--is-moving [data-type] {
127+
cursor: move;
128+
}
125129
}
126130

127131
/**
@@ -345,7 +349,6 @@
345349
}
346350

347351
@keyframes spin {
348-
349352
to {
350353
transform: rotate(360deg);
351354
}

0 commit comments

Comments
 (0)