TweenMax动画不适用于具有常见java脚本文件的多个页面(TweenMax animation is not working for multiple pages with common jav

编程入门 行业动态 更新时间:2024-10-10 02:16:48
TweenMax动画不适用于具有常见java脚本文件的多个页面(TweenMax animation is not working for multiple pages with common java script file)

例如,

主页

<div id="box1">Box 1</div> <div id="box2">Box 2</div> <div id="box3">Box 3</div>

内页

<!--<div id="box1">Box 1</div> --> <div id="box2">Box 2</div> <div id="box3">Box 3</div>

JS :(主页和内页的常见Javascript。)

new TimelineMax({repeat:0}).to($('#box1'), 0.3, {css:{top:0, alpha:1,rotation:360}}) new TimelineMax({repeat:0}).to($('#box2'), 0.3, {css:{top:0, alpha:1,rotation:360}}) new TimelineMax({repeat:0}).to($('#box3'), 0.3, {css:{top:0, alpha:1,rotation:360}})

在主页上面的代码工作正常..但是对于内页..如果我删除/注释#box1,另一个#box2和#box3动画不起作用。 如何忽略#box1动画并继续使用其他动画。

For Instance,

Home page

<div id="box1">Box 1</div> <div id="box2">Box 2</div> <div id="box3">Box 3</div>

inner page

<!--<div id="box1">Box 1</div> --> <div id="box2">Box 2</div> <div id="box3">Box 3</div>

JS: (Common Javascript for home page and inner page.)

new TimelineMax({repeat:0}).to($('#box1'), 0.3, {css:{top:0, alpha:1,rotation:360}}) new TimelineMax({repeat:0}).to($('#box2'), 0.3, {css:{top:0, alpha:1,rotation:360}}) new TimelineMax({repeat:0}).to($('#box3'), 0.3, {css:{top:0, alpha:1,rotation:360}})

In Home page above code works fine..But for inner pages.. If i delete/comment #box1 the other #box2 and #box3 animation is not working. How can I ignore #box1 animation and continue with another animations.

最满意答案

我似乎无法重现这个问题。 您使用的是最新版本的GreenSock文件吗? 你可以发一个代码表或jsfiddle来演示这个问题吗?

此外,您可以大大简化您的代码:

TweenLite.to("#box1, #box2, #box3", 0.3, {top:0, alpha:1, rotation:360});

你的代码并没有“错误” - 只是冗长。 如果您没有进行排序,那么您并不需要使用TimelineMax(尽管如果您更喜欢该工作流程,它会非常好)。 但是,如果您打算对这些动画进行排序,则可以使用TimelineMax的staggerTo()方法轻松完成,如下所示:

new TimelineMax().staggerTo(["#box1", "#box2", "#box3"], 0.3, {top:0, alpha:1, rotation:360}, 0.3);

使用最后一个参数来控制交错/间距。

再次,确保您已获得最新版本 ,并且您正在该内页上加载CSSPlugin和TweenLite。

I can't seem to reproduce that issue. Are you using the latest version of the GreenSock files? Could you post a codepen or jsfiddle that demonstrates the problem?

Also, you could greatly simplify your code:

TweenLite.to("#box1, #box2, #box3", 0.3, {top:0, alpha:1, rotation:360});

Your code wasn't "wrong" - just verbose. And if you're not doing sequencing, you don't really need to use TimelineMax (although it's perfectly fine if you prefer that workflow). If you meant to sequence those animations, though, you could do that easily using TimelineMax's staggerTo() method like this:

new TimelineMax().staggerTo(["#box1", "#box2", "#box3"], 0.3, {top:0, alpha:1, rotation:360}, 0.3);

Use that last parameter to control the stagger/spacing.

Again, make sure you've got the latest version and that you're loading CSSPlugin and TweenLite on that inner page.

更多推荐

本文发布于:2023-08-02 21:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1381368.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   脚本   不适用于   常见   页面

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!