【发布时间】:2015-08-20 08:54:22
【问题描述】:
我以前从未使用过 GreenSock。背景图像变化很好,它会切换和缩小,但是我面临的问题如下:
- 要显示的 sprite 上的第一个背景图像无法缩放,但其他所有图像都可以,我该如何解决这个问题?
- 它似乎改变了背景,然后按比例放大和缩小。所以在背景图像的变化和缩放动画的开始之间有一个小的延迟。有没有办法收紧这一点,以便随着它的变化而扩展,使其过渡更顺畅?
JavaScript:
// Avatar animations
var avatarInterval;
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 = 11; // set the amount of avatars in the sprite image
var avatarSpeed = 1000; // set the avatar transition speed
var avatarHeight = 250; // set the height of a single avatar image
var avatarTotalHeight = 2750; // set the total height of the avatar sprite image
function startAvatarAnimation() {
var i = 0;
$(".avatars").show();
// Loop through avatar background images on sprite
avatarInterval = setInterval(function(){
i++;
if(i > avatarCount){
i = 0;
}
// Let's change the background
$(".avatars").css({'background-position' : '0 -' + (i*avatarHeight) + 'px' });
// avatar fading / pulse effect
if (fadePulse == true) {
// Now some scaling effects!
TweenMax.to(avatars, 0.1, {
css: {
// 'background-position': '0 -' + (i*avatarHeight) + 'px',
scaleX: 1.1,
scaleY: 1.1,
transformOrigin: "center center"
},
onComplete: scaleOut,
onCompleteParams: [avatars],
delay: 0.1,
ease: Power3.easeInOut
});
// Bring the scale back to normal
function scaleOut(el) {
TweenMax.to(el, 0.1, {
css: {
scaleX: 1.0,
scaleY: 1.0,
transformOrigin: "center center",
autoAlpha: 1,
},
ease: Power2.easeOut
});
}
} else {
// avatar sliding effect
}
}, avatarSpeed);
return false;
}
【问题讨论】:
-
你能把jsFiddle放在一起吗?
-
我需要建立一个新的精灵图像,给我 10 分钟,因为不能把这个放在网上。
-
jsfiddle.net/cwyv7tzo 我们开始吧,忽略图像在精灵上的位置上下移动一点
-
循环结束后,那个间隙是故意的吗?
-
不,但别担心,我在这端代码的其他函数中停止它:)
标签: javascript jquery gsap