首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JavaScript Greensock循环不按预期工作

JavaScript Greensock循环不按预期工作
EN

Stack Overflow用户
提问于 2015-08-27 14:13:42
回答 1查看 73关注 0票数 0

有人知道为什么这不起作用吗?似乎击中了第一个背景,但随后并没有改变位置。

代码语言:javascript
复制
// Avatar animations
var fadePulse           = true; // true: will fade avatar images and pulse in and out once changed
                                // false: will slide the avatars in and out 
var avatarCount         = 5;    // set the amount of avatars in the sprite image
var avatarSpeed         = 2     // set the avatar transition speed
var avatarHeight        = 250;  // set the height of a single avatar image
var avatars             = creative.avatars;
var animDuration        = 0.4;
var avatarCurrentIndex  = 0;

var avatarAni = new TimelineLite({ paused: true, repeat: -1 }); 

function startAvatarAnimation() {
    show(avatars);
    avatarAni.to(avatars, animDuration, {
        scaleX: 1, // 1.1 (for bouncing)
        scaleY: 1, // 1.1 (for bouncing)
        ease: Power3.easeIn,
        onComplete: onCompleteScaleIn
    });
    avatarAni.to(avatars, animDuration, {
        scaleX: 1,
        scaleY: 1,
        ease: Power3.easeOut
    });
    avatarAni.timeScale(avatarSpeed);
    avatarAni.play();
}

function onCompleteScaleIn() {
    avatarCurrentIndex ++;

    console.log(avatarCurrentIndex ++);
    if(avatarCurrentIndex <= avatarCount-1){ 
        TweenLite.set(avatars, {
            backgroundPosition: '0 -' + (avatarCurrentIndex * avatarHeight) + 'px'
        });
    } else { 
        avatarAni.pause();
        hide(avatars);
    }
}

这一切似乎都与这部分工作,通过循环和调整的位置。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-27 15:20:25

代码语言:javascript
复制
// Avatar animations
var fadePulse           = true; // true: will fade avatar images and pulse in and out once changed
                                // false: will slide the avatars in and out 
var avatarCount         = 5;    // set the amount of avatars in the sprite image
var avatarSpeed         = 2     // set the avatar transition speed
var avatarHeight        = 250;  // set the height of a single avatar image
var avatars             = creative.avatars;
var animDuration        = 0.4;
var avatarCurrentIndex  = 0;
var i = 0;

var avatarAni = new TimelineMax({ paused: true, repeat: -1 });

function startAvatarAnimation() {
    show(creative.avatars);

    avatarAni.to(avatars, animDuration, { scaleX: 1, scaleY: 1, ease: Power3.easeIn, onComplete: onCompleteScaleIn });
    avatarAni.to(avatars, animDuration, { scaleX: 1, scaleY: 1, ease: Power3.easeOut });

    avatarAni.timeScale(avatarSpeed);
    avatarAni.play();
}

function onCompleteScaleIn() {
    i++;

    if(i <= avatarCount-1){ 
        TweenMax.set(avatars, { backgroundPosition: '0 -' + (i * avatarHeight) + 'px' });
    } else { 
        avatarAni.pause();
        hide(avatars);
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32251758

复制
相关文章

相似问题

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