【问题标题】:Mootools 1.3.1: chain animations and animate 2 elements synchronislyMootools 1.3.1:链式动画和同步动画 2 个元素
【发布时间】:2011-11-22 15:32:51
【问题描述】:

我想同时为div#w_xxxdiv#w_xxx img 设置动画。

它们应该变大,然后它们应该达到原来的宽度和高度。

问题是,mootools 会同时播放所有动画,所以我看不到动画,我尝试了一些来自 mootools 的 .chainfunction,但我没有得到它的工作。

我的代码如下所示:

$("w_"+current_item+"").set('morph', {
            duration: 1000,
            transition: Fx.Transitions.Bounce.easeOut
        });
        $("w_"+current_item+"").morph({
                    'opacity': '1',
                    'width': 366,
                    'height': 240,
                    'z-index': '100'
        });

        $$("div#w_"+current_item+" img").set('morph', {
            duration: 1000,
            transition: Fx.Transitions.Bounce.easeOut
        });
        $$("div#w_"+current_item+" img").morph({
                    'opacity': '1',
                    'width': 366,
                    'height': 240,
                    'z-index': '100'
        });

        $("w_"+current_item+"").set('morph', {
            duration: 1000,
            transition: Fx.Transitions.Bounce.easeOut
        });
        $("w_"+current_item+"").morph({
                    'opacity': '1',
                    'width': 183,
                    'height': 120,
                    'z-index': '100'
        });

        $$("div#w_"+current_item+" img").set('morph', {
            duration: 1000,
            transition: Fx.Transitions.Bounce.easeOut
        });
        $$("div#w_"+current_item+" img").morph({
                    'opacity': '1',
                    'width': 183,
                    'height': 120,
                    'z-index': '100'
        });

【问题讨论】:

    标签: javascript animation mootools mootools-fx


    【解决方案1】:

    您应该查看来自 MooTools-more 的 Fx.Elementshttp://mootools.net/docs/more/Fx/Fx.Elements,它旨在在统一的计时器上运行多个动画。

    http://jsfiddle.net/dimitar/tC4V4/

    // mock your current_item... 
    var current_item = 1;
    
    var w = document.id("w_" + current_item);
    new Fx.Elements($$(w, w.getElement("img")), {
        onComplete: function() {
            console.log("done");
        },
        duration: 4000,
        transition: Fx.Transitions.Bounce.easeOut,
        link: "chain"
    }).start({
        0: {
            'opacity': '1',
            'width': 366,
            'height': 240,
            'z-index': '100'
        },
        1: {
            'opacity': '1',
            'width': 183,
            'height': 120,
            'z-index': '100'
    
        }   
    }).start({
        0: {
            opacity: 0
        }  
    
    });
    

    同样地,它支持链接:链,因此您可以链接事物或等待等。

    【讨论】:

    • 谢谢 =) 如果您使用 jquery 工作了这么多年,mootools 的备用文档会令人沮丧
    • 好吧,似乎 div 和图像没有调整到它们的旧值。我的结构也像
    • 首先读取旧值,将它们存储到一个对象中并将它们传回:)。顺便说一句,如果可用,为什么不使用比例变换 - 它们会更平滑。如果没有,请使用 mootools。
    • 当然,我的只是一个例子:)
    猜你喜欢
    • 2012-08-21
    • 2014-02-02
    • 2017-09-03
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 2017-12-04
    • 2014-08-19
    • 1970-01-01
    相关资源
    最近更新 更多