官术网_书友最值得收藏!

Animating the card list

There are three missing animations for our hand--when a card is either added or removed from the player hand, and when it is moved. When the turn begins, the player will draw a card. It means that we will add a card to the hand cards list, and it will slide from the right into the hand. When a card is played, we want it to go up and grow bigger.

To animate a list of elements, we will need another special component--<transition-group>. It animates the children when they are added, removed, and moved. In a template, it looks like this:

<transition-group>
<p v-for="item of items" />
</transition-group>

Unlike the <transition> element, the transition group will appear in the DOM as a <span> element by default. You can change the HTML element with the tag prop:

<transition-group tag="ul">
<li v-for="item of items" />
</transition-group>

In the template of our hand component, enclose the card components with a transition group, specify the name of the transition that we will call "card", and add the "cards" CSS class:

<transition-group name="card" tag="p" class="cards">
<card v-for="card of cards" :def="card.def" @play="handlePlay(card) />
</transition-group>

Before we can continue, there is one important thing missing--the children of the transition group must be identified by a unique key.

主站蜘蛛池模板: 牡丹江市| 新平| 富蕴县| 阿拉善右旗| 灵武市| 拜泉县| 连云港市| 新宁县| 双桥区| 金堂县| 天等县| 乐平市| 兴和县| 威宁| 中阳县| 黑山县| 东丽区| 苗栗市| 上思县| 游戏| 钟山县| 萝北县| 澎湖县| 江永县| 洪洞县| 敦煌市| 长岛县| 侯马市| 西安市| 高密市| 余干县| 贡嘎县| 育儿| 响水县| 太白县| 凌海市| 瑞昌市| 开阳县| 龙井市| 澄城县| 平顺县|