使用StateModifier在famousJS中实现无限动画

时间:2015-05-16 12:40:59

标签: scale infinite famo.us

我想要一个像心脏一样的圆圈,一个脉冲动画。因此,圆首先扩展到75%,然后扩展到100%。我想让它成为一个无限循环。

代码:

var Engine = require('famous/core/Engine');
var Surface = require('famous/core/Surface');
var Transform = require('famous/core/Transform');
var StateModifier = require('famous/modifiers/StateModifier');
var Easing = require('famous/transitions/Easing');

var mainContext = Engine.createContext();

var surface = new Surface({
    size: [180, 180],
    properties: {
        backgroundColor: 'grey',
        borderRadius: '50%'
    }
});

var stateModifier = new StateModifier();

stateModifier.setTransform(
    Transform.scale(0.7, 0.7, 1),
    { duration : 1050 }
);

stateModifier.setTransform(
    Transform.scale(1, 1, 1),
    { duration : 450 }
);

mainContext.add(stateModifier).add(surface);

任何人都知道如何实现这个目标?

1 个答案:

答案 0 :(得分:1)

使用回调并将setTransform包装在一个函数中,以便在完成后让每个回调相互调用。

运行代码段示例

define('main', function(require, exports, module) {
  var Engine = require('famous/core/Engine');
  var Surface = require('famous/core/Surface');
  var Transform = require('famous/core/Transform');
  var StateModifier = require('famous/modifiers/StateModifier');
  var Easing = require('famous/transitions/Easing');

  var mainContext = Engine.createContext();

  var surface = new Surface({
    size: [180, 180],
    properties: {
      backgroundColor: 'grey',
      borderRadius: '50%'
    }
  });

  var stateModifier = new StateModifier();

  function min() {
    stateModifier.setTransform(
      Transform.scale(0.7, 0.7, 1), {
        duration: 1050
      },
      max
    );
  }

  function max() {
    stateModifier.setTransform(
      Transform.scale(1, 1, 1), {
        duration: 450
      },
      min
    );
  }

  mainContext.add(stateModifier).add(surface);

  surface.on('deploy', function() {
    min();
  });


});
require(['main']);
<script src="http://requirejs.org/docs/release/2.1.16/minified/require.js"></script>
<script src="http://code.famo.us/lib/requestAnimationFrame.js"></script>
<script src="http://code.famo.us/lib/classList.js"></script>
<script src="http://code.famo.us/lib/functionPrototypeBind.js"></script>

<link rel="stylesheet" type="text/css" href="http://code.famo.us/famous/0.3.5/famous.css" />
<script src="http://code.famo.us/famous/0.3.5/famous.min.js"></script>