Feat: swipe gauche/droite sur Play mobile
All checks were successful
Deploy / Deploy to Production (push) Successful in 19s
All checks were successful
Deploy / Deploy to Production (push) Successful in 19s
Même logique que les touches fléchées : navigation entre jeux, aux limites passage à la slide précédente/suivante via slideTo. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
44912c1d2f
commit
773be2840c
1 changed files with 47 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
<script>
|
||||
import { onMount } from 'svelte'
|
||||
import { slides } from '@state/slides.svelte'
|
||||
import { slideTo } from '@router'
|
||||
import ResponsivePicture from '@components/ui/ResponsivePicture.svelte'
|
||||
import { t } from '@i18n'
|
||||
|
||||
|
|
@ -87,6 +88,41 @@
|
|||
}
|
||||
}
|
||||
|
||||
// --- Touch (mobile) ---
|
||||
// Même logique que le clavier : navigation entre jeux en priorité,
|
||||
// aux limites on laisse passer vers la slide précédente/suivante.
|
||||
const TOUCH_THRESHOLD = 50
|
||||
let touchStartX = 0
|
||||
|
||||
function onTouchStart(e) {
|
||||
if (!isActive) return
|
||||
touchStartX = e.touches[0].clientX
|
||||
}
|
||||
|
||||
function onTouchEnd(e) {
|
||||
if (!isActive) return
|
||||
const deltaX = touchStartX - e.changedTouches[0].clientX
|
||||
if (Math.abs(deltaX) < TOUCH_THRESHOLD) return
|
||||
|
||||
if (deltaX > 0) {
|
||||
// Swipe gauche → jeu suivant, ou slide suivante si fin de liste
|
||||
if (currentIndex < games.length - 1) {
|
||||
selectGame(currentIndex + 1)
|
||||
} else {
|
||||
const next = slides.all[slides.activeIndex + 1]
|
||||
if (next) slideTo(next.path)
|
||||
}
|
||||
} else {
|
||||
// Swipe droite → jeu précédent, ou slide précédente si début de liste
|
||||
if (currentIndex > 0) {
|
||||
selectGame(currentIndex - 1)
|
||||
} else {
|
||||
const prev = slides.all[slides.activeIndex - 1]
|
||||
if (prev) slideTo(prev.path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Réinitialisation quand on quitte la slide
|
||||
$effect(() => {
|
||||
if (!isActive) {
|
||||
|
|
@ -103,8 +139,12 @@
|
|||
|
||||
onMount(() => {
|
||||
window.addEventListener('keydown', onKeyDown, { capture: true })
|
||||
window.addEventListener('touchstart', onTouchStart, { capture: true, passive: true })
|
||||
window.addEventListener('touchend', onTouchEnd, { capture: true, passive: true })
|
||||
return () => {
|
||||
window.removeEventListener('keydown', onKeyDown, { capture: true })
|
||||
window.removeEventListener('touchstart', onTouchStart, { capture: true })
|
||||
window.removeEventListener('touchend', onTouchEnd, { capture: true })
|
||||
clearTimeout(t1)
|
||||
clearTimeout(t2)
|
||||
clearTimeout(t3)
|
||||
|
|
@ -425,7 +465,6 @@
|
|||
text-align: center;
|
||||
}
|
||||
|
||||
.play-carousel-item.active button img,
|
||||
.play-carousel-item.active button :global(picture img) {
|
||||
border: 4px solid var(--color-primary);
|
||||
border-radius: 25%;
|
||||
|
|
@ -454,6 +493,13 @@
|
|||
.play-carousel {
|
||||
grid-area: 14/4 / span 3 / span 13;
|
||||
}
|
||||
|
||||
.play-carousel-item :global(img) {
|
||||
width: clamp(70px, 18.41vw, 355px);
|
||||
}
|
||||
.play-carousel-item.active :global(img) {
|
||||
width: clamp(90px, 18.41vw, 355px);
|
||||
}
|
||||
}
|
||||
|
||||
/* Reduced motion */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue