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

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.

主站蜘蛛池模板: 安龙县| 巨野县| 宜丰县| 津市市| 南溪县| 庆云县| 牡丹江市| 微山县| 乐平市| 泰顺县| 黑山县| 固阳县| 桂东县| 泊头市| 左贡县| 潜山县| 肥城市| 宜兰县| 赤壁市| 津南区| 辛集市| 万载县| 格尔木市| 水城县| 巴林左旗| 黑水县| 文登市| 武宁县| 襄樊市| 商都县| 莱州市| 元谋县| 宜黄县| 柳林县| 长泰县| 永宁县| 台江县| 墨脱县| 龙游县| 香格里拉县| 武陟县|