简体   繁体   English

使用 GSAP ScrollTrigger 触发 animation

[英]Trigger animation with GSAP ScrollTrigger

I've created a CSS3 Animation with a scroll trigger that I'd need in GSAP ScrollTrigger since AddEventListener('scroll'... is not compatible with GSAP because it uses some different mechanisms for scrolling.我创建了一个带有滚动触发器的 CSS3 Animation,因为AddEventListener('scroll'...与 GSAP 不兼容,因为它使用一些不同的滚动机制。

This is the current animation that I've created: https://jsfiddle.net/nyofa3cb/13/这是我创建的当前 animation: https://jsfiddle.net/nyofa3cb/13/

This is what I've tried to do in GSAP ScrollTrigger, but hasn't worked:这是我在 GSAP ScrollTrigger 中尝试做的,但没有奏效:

gsap.to('.glitch-slide', {
    keyframes: {
        "0%":   { backgroundPosition: '0 0' },
        "10%":  { backgroundPosition: '5px 0' },
        "20%":  { backgroundPosition: '-5px 0' },
        "30%":  { backgroundPosition: '15px 0' },
        "40%":  { backgroundPosition: '-25x 0' },
        "50%":  { backgroundPosition: '-50px 0' },
        "60%":  { backgroundPosition: '0 -20px' },
        "70%":  { backgroundPosition: '-60px -20px' },
        "80%":  { backgroundPosition: '0 0' },
        "90%":  { backgroundPosition: '20px 0'},
        "100%": { backgroundPosition: '0 0'},
         easeEach: 'expo.inOut'
       },
       ease: 'none',
       duration: 1
})

You can add your keyframes to css and create class that init this animation.您可以将关键帧添加到 css 并创建 class 以初始化此 animation。 With that all you need to start this animation is to add created class to element using ScrollTrigger.有了这个,你需要启动这个 animation 就是使用 ScrollTrigger 将创建的 class 添加到元素。

onEnter进入

onEnter: ({progress, direction, isActive}) => documentQuerySelector('.my-selector').classList.add('active')

or或者

toggleClass: {targets: ".my-selector", className: "active"}

Here are examples https://greensock.com/docs/v3/Plugins/ScrollTrigger以下是示例https://greensock.com/docs/v3/Plugins/ScrollTrigger

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM