YUI3 中的同步动画?

发布于 2024-08-17 19:50:57 字数 162 浏览 5 评论 0原文

yui3 中是否可以同步多个动画以便它们一起进展?类似于 jquery 1.4 路线图中提到的内容以及本示例中演示的内容 http://ejohn.org/files/同步

Is it possible in yui3 to synchronize multiple animations so they progress together? Something similar to what is mentioned in the jquery 1.4 roadmap and demonstrated in this example http://ejohn.org/files/sync.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弄潮 2024-08-24 19:50:57

因为我讨厌找到关于 SO 的问题的非答案,所以我想我会参与其中。

感谢错误报告中的信息(http://yuilibrary.com/projects/yui3/ticket/2528886)

这是我所拥有的:两个盒子,并排。我希望左边的盒子缩小(宽度方向),同时右边的盒子变大。

(由于我前段时间做出的一些不幸的决定,我使用 div,带有 float:left/float right 和overflow:hidden,但这应该适用于大多数其他配置。)

这就是我所做的:


var anim = new Y.Anim({
        duration: 1.0
});

var elmLeftBox = Y.one('#leftBox');
var elmRightBox = Y.one('#rightBox');

var intWidth = parseInt(elmLeftBox.getComputedStyle('width'), 10);

anim.on('tween', function(e) {
    var elapsedTime = this.get('elapsedTime');
    var duration = this.get('duration');
    var easing = this.get('easing');

    var leftPos = easing(elapsedTime, intWidth, (-1 * intWidth), duration*1000);
    var rightPos = easing(elapsedTime, 0, intWidth, duration*1000);
    elmLeftBox.setStyle('width', leftPos);
    elmRightBox.setStyle('width', rightPos);
});

anim.on('end', function(evt) {
    //clean up after myself - don't want hardcoded widths
    elmLeftBox.setStyle('width', 0);
    elmRightBox.setStyle('width', '100%');
});

anim.run();

完美工作。祝你好运!

Since I hate to find non-answers to questions on SO, I thought I'd pitch in.

I figured this out, thanks to info in a bug report (http://yuilibrary.com/projects/yui3/ticket/2528886)

Here's what I had: two boxes, side by side. I wanted the left box to shrink (width wise) and at the same time the right box to grow.

(I use divs, with float:left/float right and overflow:hidden, due to some unfortunate decisions I made some time ago, but this should work for most other configurations.)

Here's what I did:


var anim = new Y.Anim({
        duration: 1.0
});

var elmLeftBox = Y.one('#leftBox');
var elmRightBox = Y.one('#rightBox');

var intWidth = parseInt(elmLeftBox.getComputedStyle('width'), 10);

anim.on('tween', function(e) {
    var elapsedTime = this.get('elapsedTime');
    var duration = this.get('duration');
    var easing = this.get('easing');

    var leftPos = easing(elapsedTime, intWidth, (-1 * intWidth), duration*1000);
    var rightPos = easing(elapsedTime, 0, intWidth, duration*1000);
    elmLeftBox.setStyle('width', leftPos);
    elmRightBox.setStyle('width', rightPos);
});

anim.on('end', function(evt) {
    //clean up after myself - don't want hardcoded widths
    elmLeftBox.setStyle('width', 0);
    elmRightBox.setStyle('width', '100%');
});

anim.run();

Works perfectly. Good luck!

无人接听 2024-08-24 19:50:57

YUI3 并不正式支持这一点,但您可以通过订阅补间事件并自行修改值来完成类似的操作。

YUI3 doesn't officially support that, but you could do something pretty similar by subscribing to the tween event and modifying the values yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文