- Vue.js 2 Web Development Projects
- Guillaume Chau
- 249字
- 2021-07-02 22:34:33
A prettier animation
We will now make a more complex but better animation, with some 3D effects. In addition to the hand, we will animate the .wrapper element (for a 3D flip) and the .card elements. The cards will start being piled up and will progressively expand to their expected position in the hand. At the end, it will animate as if the player is picking up the cards from a table.
- Start by creating new transition CSS classes with the 'hand' name instead of 'fade':
.hand-enter-active,
.hand-leave-active {
transition: opacity .5s;
}
.hand-enter,
.hand-leave-to {
opacity: 0;
}
- Change the transition name in the main template too:
<transition name="hand">
<hand v-if="!activeOverlay" :cards="testHand" />
</transition>
- Let's animate the wrapper element. Use the CSS transform property to apply a 3D transformation to the element:
.hand-enter-active .wrapper,
.hand-leave-active .wrapper {
transition: transform .8s cubic-bezier(.08,.74,.34,1);
transform-origin: bottom center;
}
.hand-enter .wrapper,
.hand-leave-to .wrapper {
transform: rotateX(90deg);
}
The right rotating axis is the horizontal one, which is x. This will animate the cards just as if they were being picked up by the player. Note that there is a cubic-bezier easing function defined to make the animation smoother.
- Finally, animate the cards themselves by setting a negative horizontal margin so that they will seem to be piled up:
.hand-enter-active .card,
.hand-leave-active .card {
transition: margin .8s cubic-bezier(.08,.74,.34,1);
}
.hand-enter .card,
.hand-leave-to .card {
margin: 0 -100px;
}
Now, if you hide and show the hand with the browser console like we did before, it will have a nice animation.
推薦閱讀
- 少兒人工智能趣味入門:Scratch 3.0動畫與游戲編程
- Fundamentals of Linux
- 無代碼編程:用云表搭建企業數字化管理平臺
- AngularJS Web Application Development Blueprints
- 軟件測試項目實戰之性能測試篇
- 跟小海龜學Python
- Learning ELK Stack
- Scala Reactive Programming
- Access 2010數據庫應用技術實驗指導與習題選解(第2版)
- TypeScript圖形渲染實戰:2D架構設計與實現
- Visual Basic程序設計實驗指導及考試指南
- 視窗軟件設計和開發自動化:可視化D++語言
- Dart:Scalable Application Development
- Apache Solr for Indexing Data
- 川哥教你Spring Boot 2實戰