简体   繁体   English

GSAP TweenMax - 无法访问时间线内的变量

[英]GSAP TweenMax - not able to access variables inside timelines

I am creating scroll based animations with GSAP.我正在使用 GSAP 创建基于滚动的动画。 I am creating a timeline for a tween, then updating the progress of the timeline based on how far you have scrolled through a set container.我正在为补间创建一个时间线,然后根据您滚动设置容器的距离更新时间线的进度。 I am able to create this effect by using CSS values such as x or y for example for CSS transform properties.我可以通过使用诸如 x 或 y 之类的 CSS 值来创建这种效果,例如用于 CSS 转换属性。 I cannot access dynamic variables inside an each function for the elements I wish to animate and set the CSS properties to tween through these.我无法访问每个函数内的动态变量,以获取我希望设置动画的元素并将 CSS 属性设置为通过这些进行补间。

My code would be too long to copy and paste here - so will link code pens for my problem.我的代码太长而无法在此处复制和粘贴 - 因此将为我的问题链接代码笔。

Here is my working version:这是我的工作版本:

Using the x and y values to tween CSS transform properties works completely fine.使用 x 和 y 值对 CSS 变换属性进行补间工作完全没问题。 This is the result I want at the end.这是我最后想要的结果。

CODE HERE:
https://codepen.io/ellisclicky/pen/rqPYmw

Here is my version that I want to work, where I am using data attributes from an HTML element to determine what CSS property to animate:这是我想要工作的版本,我使用来自 HTML 元素的数据属性来确定要设置动画的 CSS 属性:

I cannot access the variable and I can't figure out why - I have googled everything under the sun about this but can't find anything.我无法访问该变量,我无法弄清楚原因 - 我在阳光下搜索了所有关于此的内容,但找不到任何内容。

CODE HERE:
https://codepen.io/ellisclicky/pen/NOowMx

Any help is very appreciated.非常感谢任何帮助。

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

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