我想要暂停()我的翻译动画并让它立即在最终位置结束。 halt()当前停止当前的动画。
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: [100, 100],
content: 'click me to halt',
properties: {
color: 'white',
textAlign: 'center',
backgroundColor: '#FA5C4F'
}
});
var stateModifier = new StateModifier({
origin: [0.5, 0]
});
mainContext.add(stateModifier).add(surface);
stateModifier.setTransform(
Transform.translate(0, 300, 0),
{ duration : 8000, curve: 'linear' }
);
surface.on('click', function() {
stateModifier.halt();
surface.setContent('halted');
});
答案 0 :(得分:1)
你的解决方案看起来确实非常糟糕。为什么不在没有转换的情况下应用相同的转换..
surface.on('click', function() {
stateModifier.halt();
stateModifier.setTransform(Transform.translate(0, 300, 0));
surface.setContent('halted');
});
编辑:
更好的是你可以直接进行最终的转换..
surface.on('click', function() {
stateModifier.setTransform(stateModifier.getFinalTransform());
surface.setContent('halted');
});
答案 1 :(得分:0)
我发现了这个,至少在0.2.0之前。
您可以使用Translate.set()使用非常大的数字来设置最终状态,以强制动画的最后状态。
很高兴在未来的Famo.us版本中以halt()的方式看到对此的支持
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: [100, 100],
content: 'click me to halt',
properties: {
color: 'white',
textAlign: 'center',
backgroundColor: '#FA5C4F'
}
});
var stateModifier = new StateModifier({
origin: [0.5, 0]
});
mainContext.add(stateModifier).add(surface);
stateModifier.setTransform(
Transform.translate(0, 300, 0),
{ duration : 8000, curve: 'linear' }
);
surface.on('click', function() {
// This forces the translate animation to its end state
var translate = stateModifier._transformState.translate;
translate.set(translate.get(Number.MAX_VALUE));
surface.setContent('halted');
});