explode
lets you break apart your old and new
templates and animate the pieces separately. First we show examples,
and then below we document all the options in detail.
Click the button to see the demo:
The transition rule:
this.transition(
this.childOf('#explode-demo-1'),
this.use(
'explode',
{
pickOld: 'h3', // Find an "h3" in the old template. This
// can be any CSS selector.
use: ['toUp', { duration }], // And animate it upward. This can
// be any arbitrary transition, and
// its optional parameters.
},
{
pickNew: 'h3', // Find an "h3" in the new template
use: ['toDown', { duration }], // And animate it downward.
},
{
// For everything else that didn't match the above, use a
// fade. I'm giving the fade half as much duration because fade
// includes both fading out and fading in steps, each of which
// spends `duration` milliseconds.
use: ['fade', { duration: duration / 2 }],
},
),
);
The template:
<div id="explode-demo-1">
<button type="button" >Toggle Detail View</button>
<div class="details">
<h3>Details</h3>
<p>
Bacon ipsum dolor amet shank pork belly boudin flank
prosciutto alcatra andouille pig short ribs biltong kevin
salami tail turkey beef ribs.
</p>
</div>
<div class="overview">
<h3>Welcome</h3>
<p>This is the overview.</p>
</div>
</div>
Click "Shuffle":
The transition rule:
this.transition(
this.childOf('#explode-demo-2'),
this.use('explode', {
matchBy: 'data-photo-id', // matchBy will look for the same
// HTML attribute value in both
// the old and new elements, and
// for each matching pair, it
// runs the given transition.
// fly-to is a built in transition that animate the element
// moving from the position of oldElement to the position of
// newElement.
use: ['fly-to', { duration, easing: 'spring' }],
}),
);
The template:
<div id="explode-demo-2">
<button type="button" >Shuffle</button>
<LiquidBind @value= as |photosVersion|>
<img src= alt="a random person" data-photo-id=>
</LiquidBind>
</div>
explode
accepts any number of arguments. Each argument
must be an object. Each object describes one piece of the
transition.
Each piece must have a use
property, which can be:
"toLeft"
["toLeft", { duration: 100 }]
function(){ return animate(this.newElement, { opacity: 0 }); }
[myTransitionFunction, { duration: 400 }]
Each piece may also have one of these options:
pick
property whose value is a CSS selector
that will be matched against both the old and new elements.pickOld
property whose value is a CSS selector
that will be matched against the old elements. May be combined with pickNew
.pickNew
property whose value is a CSS selector
that will be matched against the old elements. May be combined with pickOld
.matchBy
property whose value is the name of an
HTML attribute that will be matched against both old and new
elements for pairwise transitions.A piece that has only a use
and no further options may
be used to control everything else that doesn't match another section.