Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. GSAP scrolltrigger / lottie animation

GSAP scrolltrigger / lottie animation

Scheduled Pinned Locked Moved General Discussion
5 Posts 3 Posters 320 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ffingerF Offline
    ffingerF Offline
    ffinger
    wrote on last edited by ffinger
    #1

    Hey laythemers,

    I just tried to work with GSAP framework and the Scrolltrigger plugin and it works fine so far.
    But I fail to run a lottie animation with the Scrolltrigger plugin.

    GSAP Docs provide a little helper function for this, which I used:

    function LottieScrollTrigger(vars) {
        let playhead = { frame: 0 },
            target = gsap.utils.toArray(vars.target)[0],
            speeds = { slow: "+=2000", medium: "+=1000", fast: "+=500" },
            st = { trigger: target, pin: true, start: "top top", end: speeds[vars.speed] || "+=1000", scrub: 1 },
            ctx = gsap.context && gsap.context(),
            animation = lottie.loadAnimation({
                container: target,
                renderer: vars.renderer || "svg",
                loop: false,
                autoplay: false,
                path: vars.path,
                rendererSettings: vars.rendererSettings || { preserveAspectRatio: 'xMidYMid slice' }
            });
        for (let p in vars) { // let users override the ScrollTrigger defaults
            st[p] = vars[p];
        }
        animation.addEventListener("DOMLoaded", function () {
            let createTween = function () {
                animation.frameTween = gsap.to(playhead, {
                    frame: animation.totalFrames - 1,
                    ease: "none",
                    onUpdate: () => animation.goToAndStop(playhead.frame, true),
                    scrollTrigger: st
                });
                return () => animation.destroy && animation.destroy();
            };
            ctx && ctx.add ? ctx.add(createTween) : createTween();
            // in case there are any other ScrollTriggers on the page and the loading of this Lottie asset caused layout changes
            ScrollTrigger.sort();
            ScrollTrigger.refresh();
        });
        return animation;
    }
    

    I deactivated lazyloading, all kind of transition, and activated compatibility mode. I think it has something to do with the addEventListener "DOMloaded"? But I can't get my head around this. Anybody a hint to solve this?

    Cheers
    Felix

    https://www.felixfinger.de

    1 Reply Last reply
    0
    • ffingerF Offline
      ffingerF Offline
      ffinger
      wrote on last edited by
      #2

      Ok I just figured it out myself. For everyone having the same issue: I haven't loaded the lottie web framework, but only the lottie player. So far I only embedded lottie animations via the player and didn't know I need the framework :)

      So you just need to load the web framework instead of the player in your "Custom CSS & HTML" -> "Custom <head> content" Tab:

      <script src="https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.12.1/lottie.min.js"></script>
      

      Cheers!

      https://www.felixfinger.de

      1 Reply Last reply
      0
      • arminunruhA Offline
        arminunruhA Offline
        arminunruh
        Global Moderator
        wrote on last edited by
        #3

        nice! i see more and more people wanting to use lottie mmh

        1 Reply Last reply
        1
        • moND0711M Offline
          moND0711M Offline
          moND0711
          wrote on last edited by
          #4

          Yeah, I'm one of them too ;-)

          1 Reply Last reply
          0
          • arminunruhA Offline
            arminunruhA Offline
            arminunruh
            Global Moderator
            wrote on last edited by arminunruh
            #5

            :D

            probably in the code example of the first post here you need to use

            window.laytheme.on('newpageshown', function(){
            ...your code
            })
            

            instead of

            animation.addEventListener("DOMLoaded", function () {
            ...your code
            })
            
            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            I also code custom websites or custom Lay features.
            šŸ’æ Email me here: šŸ’æ
            info@laytheme.com

            Before you post:
            1. When using a WordPress Cache plugin, disable it or clear your cache.
            2. Update Lay Theme and all Lay Theme Addons
            3. Disable all Plugins
            4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

            This often solves issues you might run into

            When you post:
            1. Post a link to where the problem is
            2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
            3. If the problem is difficult to explain, post screenshots / link to a video to explain it
            Online Users
            S
            svinder
            Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
            laytheme.com
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Recent
            • Tags
            • Popular
            • Users
            • Search