Jump to content
Search Community

Moritz L

Premium
  • Posts

    7
  • Joined

  • Last visited

Community Answers

  1. Moritz L's post in Sveltekit Page Transition with GSAP (incl. ScrollSmoother) was marked as the answer   
    I solved my issue when I completely refactored how I implemented scroll trigger. I moved all the logic to +layout.svelte like so: 
     
    <script> import '../app.css' import { gsap } from 'gsap' import { ScrollSmoother } from 'gsap/dist/ScrollSmoother' import { ScrollTrigger } from 'gsap/dist/ScrollTrigger' import BaseNav from '$lib/components/base-nav.svelte' import { onMount } from 'svelte' export let data /** * @type {ScrollSmoother} */ let smoother if (typeof window !== 'undefined') { gsap.registerPlugin(ScrollTrigger, ScrollSmoother) } onMount(() => { smoother = ScrollSmoother.create({ smooth: 1, effects: false }) }) /** * @param {HTMLElement} node * @param {Object} options * @param {number} [options.duration] * @param {number} [options.delay] */ // out transition function wipe(node, { duration = 250, delay = 0 }) { // pulling "from" page out of document flow and positioning it absolutely over "to" page gsap.set(node, { position: 'fixed', inset: 0, width: '100%', height: window.innerHeight, zIndex: 9999, overflow: 'hidden', backgroundColor: '#fff', opacity: 1, visibility: 'visible' }) // prevent scrollY from jumping to top of page gsap.set(node.firstChild, { y: -window.scrollY }) // make sure "to" page is scrolled to top smoother.scrollTop(0) const tl = gsap.timeline({ delay, defaults: { duration: duration / 1000 } }) tl.to(node, { height: 0, ease: 'power4.inOut' }) return { duration, delay, /** * The function to call on each animation frame. * @param {number} t - The current tick value. */ tick: (t) => { tl.progress(1 - t) } } } </script> <BaseNav /> <div id="smooth-wrapper"> <div id="smooth-content"> {#key data.url.pathname} <main out:wipe={{ duration: 2000 }} on:outroend={() => ScrollTrigger.refresh()}> <slot /> </main> {/key} </div> </div> I hope that helps anyone who tries to work with Svelte transitions and ScrollSmoother.
  2. Moritz L's post in Looping image gallery horizontally but having problems animating the progress was marked as the answer   
    @Rodrigo Thanks so much for your help! Your solution on CodePen did not work and I tried the wrap helper function before. But your explanation has led me to the solution: After setting up the loop timeline, I am instantly jumping to the end of the timeline like so: 
     
    const loop = horizontalLoop(images, { repeat: -1, paddingRight: '24px', centerAlign: true, paused: true }) loop.progress(1) This solves my problem, because then I can also have negative progress values. I still can't quite wrap my head around it because at a certain point when constantly scrolling to the right (in a negative timeline direction) the progress will go past 0 and become negative at a certain point, right? 

    But nevertheless, it works. Here is the updated Pen: 
    See the Pen mdzLOKL by moritzlaube (@moritzlaube) on CodePen


    Thanks again for your help! It's awesome to be part of this community. 
×
×
  • Create New...