【问题标题】:Simply function with similar properties只需具有相似属性的功能
【发布时间】:2016-02-04 06:09:28
【问题描述】:

如何简化以下函数?

我有一堆具有基本相同缓动属性的补间。 我意识到这个问题相当广泛,但我还没有提出任何令人满意的问题。

    $('input').change(function() {
    if($("#radio").is(":checked")){

        var tween = new TWEEN.Tween(tween1.scale).to({ y: 4 }, 1000).start();
        tween.easing(TWEEN.Easing.Elastic.InOut);
        tween.yoyo(true);

        var tween = new TWEEN.Tween(tween2.position).to({ y: 0.05 }, 1000).start();
        tween.easing(TWEEN.Easing.Elastic.InOut);
        tween.yoyo(true);

        var tween = new TWEEN.Tween(tween3.scale).to({ y: 6 }, 1000).start();
        tween.easing(TWEEN.Easing.Elastic.InOut);
        tween.yoyo(true);

        ...

 }
 });

【问题讨论】:

    标签: javascript jquery three.js tween


    【解决方案1】:

    最经典的方式是声明一个函数:

    function doTween(attr, y) {
        var tween = new TWEEN.Tween(attr).to({ y: y }, 1000).start();
        tween.easing(TWEEN.Easing.Elastic.InOut);
        tween.yoyo(true);
    }
    

    并调用使用

    doTween( tween1.scale, 4 );
    doTween( tween2.position, 0.05 );
    doTween( tween3.scale, 6 );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-07
      • 2015-05-28
      • 1970-01-01
      • 1970-01-01
      • 2014-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多