[英]Chaining animations smoothly for several elements in jQuery
我正在尝试通过使用jQuery为跨域目的依次为几个堆叠的图像设置动画来重新创建地图的放大效果。
到目前为止,我取得了一些成就,通过为每个图像使用延迟和两个单个动画(A和B日志)对动画进行排队,以便通过缩放在图像之间生成平滑过渡,并在下一个图像上使它们淡入淡出。
$('img:not(:last-child)') /* All images but farest zoom */
.reverse() /* From last to first */
.each(function (index) {
$(this).css( /* From half size… */ {
'width': 584,
'height': 336,
'margin-left': -292,
'margin-top': -168
});
$(this).delay(index * 300).animate( /* …to actual size */ {
'width': 1168,
'height': 673,
'margin-left': -584,
'margin-top': -336
}, {
duration: 300,
easing: 'linear',
done: function () {
console.log('A:', index, new Date().getTime() - timestamp);
}
});
});
$('img:not(:first-child)') /* All images but closest zoom */
.reverse() /* From last to first */
.each(function (index) {
$(this).animate( /* Animate to double size */ {
'width': 2336,
'height': 1346,
'margin-left': -1168,
'margin-top': -673,
'opacity': 0
}, {
duration: 300,
easing: 'linear',
done: function () {
console.log('B:', index, new Date().getTime() - timestamp);
$(this).remove(); /* Remove the elment once completed */
}
});
});
众所周知,jQuery不支持在单个队列中将不同DOM元素的动画排入队列,这导致了这种复杂的解决方案。
请检查此小提琴 。
如您所见,一旦图像完全加载并单击地图,动画队列就会开始。 但这远非完美。 过渡一点都不流畅,在动画之间造成一点停顿,破坏了结果。 我已经尝试了好几个小时,尝试超时,重新思考算法,强制进行线性转换,但是都没有结果。
我的主要目标是实现流畅的动画 ,然后为整个动画重新创建全局缓动效果,例如“摇摆”,并随着中间图像的动画化而逐渐加快速度。
因此,我花了最后几个小时来弄清楚这里的漏洞,这是您应该注入的代码
jQuery.easing = {
zoom: function( p ) {
return (3*p + Math.pow( p, 2 ))/4;
}
};
之后,您可以在代码中使用easing: 'zoom'
。
荒谬的是,在jQuery UI中有32种不同的缓动,但是没有什么可缩放的!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.