javascript - Animations in Maquette.js -
i've been looking further using maquette.js virtual dom library.
looking @ website library has functionality support animations when adding, removing, , updating dom nodes.
cannot find docs or api on do achieve this.
to make more concrete have made small sample below , here.
var ispopupshown = false; var togglepopup = function(){ ispopupshown = !ispopupshown; } var rendermaquette = function () { return h("div#container", [ h("button", { onclick: togglepopup }, ["click me"]), ispopupshown ? h("div#popup") : null ]); }
in example, clicking button open popup.
popup animate fade-in when node added dom , fade-out when node removed dom.
the documentation how animations work still in progress.
there 2 ways animation.
velocity.js
the easiest way use library velocity.js. work need to:
- add velocity.js script page
- change
h("div#popup")
h("div#popup", {enteranimation: fadein})
- add following javascript function
code:
var fadein = function(element) { element.style.opacity = 0; velocity.animate(element, {opacity: 1}, 1500, "ease-out"); };
you can view result here.
css transitions
you can use css transitions. work same angularjs , react. need following:
- include
css-transitions.min.js
script in page. script provided maquette. - change
h("div#popup")
h("div#popup", {enteranimation: "fadein"})
- change createprojector call
maquette.createprojector(document.body, rendermaquette, {transitions: csstransitions});
- add following style declarations stylesheet:
stylesheet:
.fadein { -webkit-transition: 0.5s ease-out opacity; transition: 0.5s ease-out opacity; opacity: 0; } .fadein.fadein-active { opacity: 1; }
you can view result here
Comments
Post a Comment