[编辑] Famo.us 版本 > 0.2.0 引入了“对齐”属性。
var rotation = new StateModifier({
origin:[0.5,0.5], // Set the origin to the center, this will center the rotation as well
align:[0,0], // Set the surface's origin to the upper left corner of the parent
transform: Transform.rotateZ(1), // a transform (here a rotation)
});
下面是我之前针对版本 < 0.2.0 的解决方案:
只要没有具有“大小”属性的修饰符,上下文就会被视为后备。同样,如果缺少 size 属性,修饰符不能相对于其父级定位。这是有关如何执行此操作的示例
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 mainContext = Engine.createContext();
var surface = new Surface({
size: [100, 100],
properties: {
backgroundColor: '#FA5C4F' // a silly square surface
}
});
var rotation = new StateModifier({
origin:[0.5,0.5], //center for the rotation
transform: Transform.rotateZ(1),// a transform
});
var stateModifier = new StateModifier({
origin:[0.0,0.0],//The modifier position according to the parent
size:[100,100],// The size with which the modifier can be positioned (note that using [1,1] would put the center of the square stuck to the upper left corner)
});
mainContext.add(stateModifier).add(rotation).add(surface);