Javascript 使用特定关键点路径的ractive.animate覆盖ractive.set
我正在写一个纸牌游戏,游戏状态是通过websocket从服务器传来的。当客户端收到游戏状态时,我调用Javascript 使用特定关键点路径的ractive.animate覆盖ractive.set,javascript,ractivejs,Javascript,Ractivejs,我正在写一个纸牌游戏,游戏状态是通过websocket从服务器传来的。当客户端收到游戏状态时,我调用ractive.set('game',game) 在游戏对象内部是一个有钱用户的列表。当他们的钱发生变化时,我想让数字变得生动,所以我写下: ractive.observe('game.seats.*.money', function(money, oldmoney, keypath) { ractive.animate(keypath, money); }) 不幸的是,这不起作用。我认
ractive.set('game',game)
在游戏对象内部是一个有钱用户的列表。当他们的钱发生变化时,我想让数字变得生动,所以我写下:
ractive.observe('game.seats.*.money', function(money, oldmoney, keypath) {
ractive.animate(keypath, money);
})
不幸的是,这不起作用。我认为这是因为当我观察更新时,游戏状态已经设置为新值,然后设置为新值的动画看起来什么都没有
有没有办法达到我想要的效果?FWIW-Ractive确实有能力设置对象层次结构的动画,因此您可以调用
Ractive.animate(“游戏”,游戏)
。请参阅
但假设您不想为模型的其他部分设置动画,可以使用观察者(在DOM更新之前激发)将值设置回原位,然后为其设置动画:
var animating = []
r.observe('game.seats.*.money', function(money, oldmoney, keypath, index) {
// the animation update will re-enter the observer,
// so bail if we are animating this index...
if ( animating[index] ) { return; }
animating[index] = true;
r.set(keypath, oldmoney);
r.animate(keypath, money).then(function(){
animating[index] = false;
});
});
请参见FWIW Ractive确实能够为对象层次结构设置动画,因此您可以调用
Ractive.animate(“游戏”,游戏)
。看
但假设您不想为模型的其他部分设置动画,可以使用观察者(在DOM更新之前激发)将值设置回原位,然后为其设置动画:
var animating = []
r.observe('game.seats.*.money', function(money, oldmoney, keypath, index) {
// the animation update will re-enter the observer,
// so bail if we are animating this index...
if ( animating[index] ) { return; }
animating[index] = true;
r.set(keypath, oldmoney);
r.animate(keypath, money).then(function(){
animating[index] = false;
});
});
请参见FWIW Ractive确实能够为对象层次结构设置动画,因此您可以调用
Ractive.animate(“游戏”,游戏)
。请参见
但假设您不想为模型的其他部分设置动画,可以使用观察者(在DOM更新之前激发)将值设置回原位,然后为其设置动画:
var animating = []
r.observe('game.seats.*.money', function(money, oldmoney, keypath, index) {
// the animation update will re-enter the observer,
// so bail if we are animating this index...
if ( animating[index] ) { return; }
animating[index] = true;
r.set(keypath, oldmoney);
r.animate(keypath, money).then(function(){
animating[index] = false;
});
});
请参见FWIW Ractive确实能够为对象层次结构设置动画,因此您可以调用
Ractive.animate(“游戏”,游戏)
。看
但假设您不想为模型的其他部分设置动画,可以使用观察者(在DOM更新之前激发)将值设置回原位,然后为其设置动画:
var animating = []
r.observe('game.seats.*.money', function(money, oldmoney, keypath, index) {
// the animation update will re-enter the observer,
// so bail if we are animating this index...
if ( animating[index] ) { return; }
animating[index] = true;
r.set(keypath, oldmoney);
r.animate(keypath, money).then(function(){
animating[index] = false;
});
});
看