首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用GSAP ScrollTrigger触发动画

用GSAP ScrollTrigger触发动画
EN

Stack Overflow用户
提问于 2022-08-12 15:10:20
回答 1查看 802关注 0票数 2

我创建了一个带有滚动触发器的CSS3动画,这是我在GSAP ScrollTrigger中需要的,因为AddEventListener('scroll'...与GSAP不兼容,因为它使用了不同的滚动机制。

这是我创建的当前动画:https://jsfiddle.net/nyofa3cb/13/

这就是我在GSAP ScrollTrigger中试图做的,但没有奏效:

代码语言:javascript
复制
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
})
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-13 07:06:02

您可以将关键帧添加到css中,并创建包含此动画的类。在此之后,启动此动画只需使用ScrollTrigger将创建的类添加到元素中。

onEnter

代码语言:javascript
复制
onEnter: ({progress, direction, isActive}) => documentQuerySelector('.my-selector').classList.add('active')

代码语言:javascript
复制
toggleClass: {targets: ".my-selector", className: "active"}

下面是示例https://greensock.com/docs/v3/Plugins/ScrollTrigger

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73336249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档