Hi awesome community,
what do I mean by this headline:
<template name="myDomObj">
<div id="obj" style="transform: translateX( {{ x }}px )"></div>
</template>
'use strict';
const template = Template[ 'myDomObj' ];
template.helpers({
x(){
const instance = Template.instance();
return instance.x.get();
}
});
template.onCreated( function(){
let instance = this;
let { initX: x = 0, initY: y = 0 } = this.data;
instance.x = new ReactiveVar( x );
instance.y = new ReactiveVar( y );
});
template.onRendered( function(){
let instance = this;
instance.$obj = instance.$( '#obj' );
instance.autorun( ( c )=>{
let y = instance.y.get();
instance.$obj.css( 'transform', 'translateY(' + y + 'px)' );
});
const FRAME_COUNT = 180;
// requestAnimationFrame Abstraction
runEveryFrame( ()=>{
let x = instance.x.get();
let y = instance.y.get();
instance.x.set( x + 1 );
instance.y.set( y + 1 );
Tracker.flush();
}, FRAME_COUNT );
});
My focus here is on the reactive vars and their change on every frame in order to change the css values for a fluent transition/animation.
My gut says its a really bad idea, but I am wondering if someone already tried to do that and mybe would like to share infos on how it performed, especially in a higher scale with more then only two vars.