Refactor: déplacer router et animations hors de state/
- src/state/router.js → src/router/index.js - src/state/animations.js → src/utils/animations.js - Ajout des alias @router et @utils dans vite.config.js - Mise à jour des imports dans Header.svelte et main.js Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
65cfba8c77
commit
51eee10c5a
5 changed files with 9 additions and 7 deletions
142
src/utils/animations.js
Normal file
142
src/utils/animations.js
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
import gsap from 'gsap'
|
||||
import { ScrollTrigger } from 'gsap/ScrollTrigger'
|
||||
|
||||
gsap.registerPlugin(ScrollTrigger)
|
||||
|
||||
/**
|
||||
* Fade in animation for page enter
|
||||
*/
|
||||
export function pageEnter(element, options = {}) {
|
||||
const defaults = {
|
||||
opacity: 0,
|
||||
y: 50,
|
||||
duration: 0.8,
|
||||
ease: 'power3.out'
|
||||
}
|
||||
|
||||
return gsap.from(element, { ...defaults, ...options })
|
||||
}
|
||||
|
||||
/**
|
||||
* Fade out animation for page exit
|
||||
*/
|
||||
export function pageExit(element, options = {}) {
|
||||
const defaults = {
|
||||
opacity: 0,
|
||||
y: -50,
|
||||
duration: 0.5,
|
||||
ease: 'power3.in'
|
||||
}
|
||||
|
||||
return gsap.to(element, { ...defaults, ...options })
|
||||
}
|
||||
|
||||
/**
|
||||
* Carousel slide animation
|
||||
*/
|
||||
export function carouselSlide(element, offset, options = {}) {
|
||||
const defaults = {
|
||||
x: `-${offset}%`,
|
||||
duration: 0.8,
|
||||
ease: 'power2.inOut'
|
||||
}
|
||||
|
||||
return gsap.to(element, { ...defaults, ...options })
|
||||
}
|
||||
|
||||
/**
|
||||
* Scroll reveal animation
|
||||
*/
|
||||
export function scrollReveal(elements, options = {}) {
|
||||
const defaults = {
|
||||
scrollTrigger: {
|
||||
trigger: elements,
|
||||
start: 'top 80%',
|
||||
toggleActions: 'play none none none'
|
||||
},
|
||||
y: 50,
|
||||
opacity: 0,
|
||||
stagger: 0.1,
|
||||
duration: 0.8,
|
||||
ease: 'power3.out'
|
||||
}
|
||||
|
||||
return gsap.from(elements, { ...defaults, ...options })
|
||||
}
|
||||
|
||||
/**
|
||||
* Fade in elements on scroll
|
||||
*/
|
||||
export function fadeInOnScroll(elements, options = {}) {
|
||||
const defaults = {
|
||||
scrollTrigger: {
|
||||
trigger: elements,
|
||||
start: 'top 80%'
|
||||
},
|
||||
opacity: 0,
|
||||
duration: 1,
|
||||
stagger: 0.2,
|
||||
ease: 'power2.out'
|
||||
}
|
||||
|
||||
return gsap.from(elements, { ...defaults, ...options })
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale animation
|
||||
*/
|
||||
export function scaleIn(element, options = {}) {
|
||||
const defaults = {
|
||||
scale: 0,
|
||||
duration: 0.5,
|
||||
ease: 'back.out(1.7)'
|
||||
}
|
||||
|
||||
return gsap.from(element, { ...defaults, ...options })
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup all ScrollTrigger instances
|
||||
*/
|
||||
export function cleanupScrollTriggers() {
|
||||
ScrollTrigger.getAll().forEach(trigger => trigger.kill())
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh ScrollTrigger (useful after content changes)
|
||||
*/
|
||||
export function refreshScrollTriggers() {
|
||||
ScrollTrigger.refresh()
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom cursor follow animation
|
||||
*/
|
||||
export function cursorFollow(cursorElement, outlineElement) {
|
||||
let cursorX = 0
|
||||
let cursorY = 0
|
||||
let outlineX = 0
|
||||
let outlineY = 0
|
||||
|
||||
const handleMouseMove = (e) => {
|
||||
cursorX = e.clientX
|
||||
cursorY = e.clientY
|
||||
}
|
||||
|
||||
const animate = () => {
|
||||
outlineX += (cursorX - outlineX) * 0.2
|
||||
outlineY += (cursorY - outlineY) * 0.2
|
||||
|
||||
gsap.set(cursorElement, { x: cursorX, y: cursorY })
|
||||
gsap.set(outlineElement, { x: outlineX, y: outlineY })
|
||||
|
||||
requestAnimationFrame(animate)
|
||||
}
|
||||
|
||||
window.addEventListener('mousemove', handleMouseMove)
|
||||
animate()
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('mousemove', handleMouseMove)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue