- Aurelia 教程
- Aurelia - 主頁
- Aurelia - 概述
- Aurelia - 環境設定
- Aurelia - 第一個應用程式
- Aurelia - 元件
- Aurelia - 元件生命週期
- Aurelia - 自定義元素
- Aurelia - 依賴項注入
- Aurelia - 配置
- Aurelia - 外掛
- Aurelia - 資料繫結
- Aurelia - 繫結行為
- Aurelia - 轉換器
- Aurelia - 事件
- Aurelia - 事件聚合器
- Aurelia - 窗體
- Aurelia - HTTP
- Aurelia - 引用
- Aurelia - 路由
- Aurelia - 歷史
- Aurelia - 動畫
- Aurelia - 對話方塊
- Aurelia - 本地化
- Aurelia - 工具
- Aurelia - 捆綁
- Aurelia - 除錯
- Aurelia - 社群
- Aurelia - 最佳實踐
- Aurelia 有用資源
- Aurelia - 快速指南
- Aurelia - 有用資源
- Aurelia - 討論
Aurelia - 動畫
在本章節中,你將學習如何使用 Aurelia 框架中的 CSS 動畫。
步驟 1 - 檢視
我們的檢視將有一個將要執行動畫的元素和一個觸發 **animateElement()** 函式的按鈕。
app.html
<template> <div class = "myElement"></div> <button click.delegate = "animateElement()">ANIMATE</button> </template>
步驟 2 - 檢視模型
在我們的 JavaScript 檔案中,我們將匯入 **CssAnimator** 外掛並將其作為依賴項注入。**animateElement** 函式將呼叫動畫器開始動畫。動畫將在下一步中建立。
import {CssAnimator} from 'aurelia-animator-css';
import {inject} from 'aurelia-framework';
@inject(CssAnimator, Element)
export class App {
constructor(animator, element) {
this.animator = animator;
this.element = element;
}
animateElement() {
var myElement = this.element.querySelector('.myElement');
this.animator.animate(myElement, 'myAnimation');
}
}
步驟 3 − 樣式
我們將在 **styles/styles.css** 檔案中編寫 CSS。**myAnimation-add** 是一個動畫的開始點,而 **myAnimation-remove** 在動畫完成後呼叫。
styles.css
.myElement {
width:100px;
height: 100px;
border:1px solid blue;
}
.myAnimation-add {
-webkit-animation: changeBack 3s;
animation: changeBack 3s;
}
.myAnimation-remove {
-webkit-animation: fadeIn 3s;
animation: fadeIn 3s;
}
@-webkit-keyframes changeBack {
0% { background-color: #e6efff; }
25% { background-color: #4d91ff; }
50% { background-color: #0058e6; }
75% { background-color: #003180; }
100% { background-color: #000a1a; }
}
@keyframes changeBack {
0% { background-color: #000a1a; }
25% { background-color: #003180; }
50% { background-color: #0058e6; }
75% { background-color: #4d91ff; }
100% { background-color: #e6efff; }
}
一旦單擊 **ANIMATE** 按鈕,背景顏色將從淺藍色變為深色。當這個動畫在三秒後完成後,該元素將淡化為其開始狀態。
廣告