Compare commits
2 commits
01adf70585
...
436a4371da
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
436a4371da | ||
|
|
37b6ca7a5f |
2 changed files with 37 additions and 7 deletions
|
|
@ -38,10 +38,11 @@
|
||||||
let resizeTimer = null
|
let resizeTimer = null
|
||||||
|
|
||||||
// Active la transition seulement après le premier paint à la bonne position.
|
// Active la transition seulement après le premier paint à la bonne position.
|
||||||
// Sans ça, un chargement sur /expertise slide depuis l'accueil.
|
// Double rAF : le premier laisse passer un paint avec le bon translateX,
|
||||||
|
// le second active is-animated — évite l'animation parasite au chargement.
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (slides.all.length > 0 && !isReady) {
|
if (slides.all.length > 0 && !isReady) {
|
||||||
requestAnimationFrame(() => { isReady = true })
|
requestAnimationFrame(() => requestAnimationFrame(() => { isReady = true }))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,31 @@
|
||||||
let sectionEl = $state(null)
|
let sectionEl = $state(null)
|
||||||
|
|
||||||
// --- Derived ---
|
// --- Derived ---
|
||||||
const isActive = $derived(slides.active?.id === 'portfolio')
|
const isActive = $derived(slides.active?.id === 'portfolio')
|
||||||
const projects = $derived(data?.projects ?? [])
|
const projects = $derived(data?.projects ?? [])
|
||||||
const currentProject = $derived(projects[currentIndex] ?? null)
|
const currentProject = $derived(projects[currentIndex] ?? null)
|
||||||
|
|
||||||
|
// Capture du hash synchrone avant que tout effect puisse le modifier
|
||||||
|
const initialHash = window.location.hash.slice(1)
|
||||||
|
|
||||||
|
// --- Ancres ---
|
||||||
|
function setAnchor(index) {
|
||||||
|
const slug = projects[index]?.slug
|
||||||
|
if (!slug) return
|
||||||
|
history.replaceState(null, '', '#' + slug)
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearAnchor() {
|
||||||
|
history.replaceState(null, '', window.location.pathname + window.location.search)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialisation depuis l'ancre URL — une seule fois quand projects est prêt
|
||||||
|
$effect(() => {
|
||||||
|
if (projects.length === 0 || !initialHash) return
|
||||||
|
const idx = projects.findIndex(p => p.slug === initialHash)
|
||||||
|
if (idx > 0) currentIndex = idx
|
||||||
|
})
|
||||||
|
|
||||||
// --- Scroll nav composable ---
|
// --- Scroll nav composable ---
|
||||||
const nav = createScrollNav({
|
const nav = createScrollNav({
|
||||||
isActive: () => isActive,
|
isActive: () => isActive,
|
||||||
|
|
@ -24,6 +45,7 @@
|
||||||
: Math.max(currentIndex - 1, 0)
|
: Math.max(currentIndex - 1, 0)
|
||||||
if (next === currentIndex) return false
|
if (next === currentIndex) return false
|
||||||
currentIndex = next
|
currentIndex = next
|
||||||
|
setAnchor(next)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -40,10 +62,17 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
// --- Effect: reset when slide deactivated ---
|
// --- Effect: reset when slide deactivated ---
|
||||||
|
// wasActive évite que clearAnchor() s'exécute au montage initial
|
||||||
|
// (isActive est false avant l'initialisation des slides)
|
||||||
|
let wasActive = false
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (!isActive) {
|
if (isActive) {
|
||||||
|
wasActive = true
|
||||||
|
} else if (wasActive) {
|
||||||
nav.reset()
|
nav.reset()
|
||||||
currentIndex = 0
|
currentIndex = 0
|
||||||
|
clearAnchor()
|
||||||
|
wasActive = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -97,7 +126,7 @@
|
||||||
<button
|
<button
|
||||||
class="portfolio-nav-item"
|
class="portfolio-nav-item"
|
||||||
class:active={i === currentIndex}
|
class:active={i === currentIndex}
|
||||||
onclick={() => { currentIndex = i }}
|
onclick={() => { currentIndex = i; setAnchor(i) }}
|
||||||
>
|
>
|
||||||
<span class="portfolio-nav-number">{String(i + 1).padStart(2, '0')}</span>
|
<span class="portfolio-nav-number">{String(i + 1).padStart(2, '0')}</span>
|
||||||
<img src={project.thumbnail} alt={project.title} />
|
<img src={project.thumbnail} alt={project.title} />
|
||||||
|
|
@ -207,7 +236,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.portfolio-nav-item.active {
|
.portfolio-nav-item.active {
|
||||||
transform: scale(1.25);
|
transform: scale(1.25) translateX(-50%);
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue