Blame view

pages/API/animation/animation.vue 3.47 KB
4b045f7c   刘淇   江阴初始化项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
  <template>
  	<view>
  		<page-head :title="title"></page-head>
  		<view class="uni-padding-wrap uni-common-mt">
  			<view class="animation-element-wrapper">
  				<view class="animation-element" :animation="animationData"></view>
  			</view>
  			<scroll-view class="animation-buttons" scroll-y="true">
  				<button class="animation-button" @tap="rotate">旋转</button>
  				<button class="animation-button" @tap="scale">缩放</button>
  				<button class="animation-button" @tap="translate">移动</button>
  				<button class="animation-button" @tap="skew">倾斜</button>
  				<button class="animation-button" @tap="rotateAndScale">旋转并缩放</button>
  				<button class="animation-button" @tap="rotateThenScale">旋转后缩放</button>
  				<button class="animation-button" @tap="all">同时展示全部</button>
  				<button class="animation-button" @tap="allInQueue">顺序展示全部</button>
  				<button class="animation-button animation-button-reset" @tap="reset">还原</button>
  			</scroll-view>
  		</view>
  	</view>
  </template>
  <script>
  	export default {
  		data() {
  			return {
  				title: 'createAnimation',
  				animationData: ''
  			}
  		},
  		onUnload(){
  			this.animationData = ''
  		},
  		onLoad() {
  			this.animation = uni.createAnimation()
  		},
  		methods: {
  			rotate: function () {
  				this.animation.rotate(Math.random() * 720 - 360).step()
  				this.animationData = this.animation.export()
  			},
  			scale: function () {
  				this.animation.scale(Math.random() * 2).step()
  				this.animationData = this.animation.export()
  			},
  			translate: function () {
  				this.animation.translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()
  				this.animationData = this.animation.export()
  			},
  			skew: function () {
  				this.animation.skew(Math.random() * 90, Math.random() * 90).step()
  				this.animationData = this.animation.export()
  			},
  			rotateAndScale: function () {
  				this.animation.rotate(Math.random() * 720 - 360)
  					.scale(Math.random() * 2)
  					.step()
  				this.animationData = this.animation.export()
  			},
  			rotateThenScale: function () {
  				this.animation.rotate(Math.random() * 720 - 360).step()
  					.scale(Math.random() * 2).step()
  				this.animationData = this.animation.export()
  			},
  			all: function () {
  				this.animation.rotate(Math.random() * 720 - 360)
  					.scale(Math.random() * 2)
  					.translate(Math.random() * 100 - 50, Math.random() * 100 - 50)
  					.skew(Math.random() * 90, Math.random() * 90)
  					.step()
  				this.animationData = this.animation.export()
  			},
  			allInQueue: function () {
  				this.animation.rotate(Math.random() * 720 - 360).step()
  					.scale(Math.random() * 2).step()
  					.translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()
  					.skew(Math.random() * 90, Math.random() * 90).step()
  				this.animationData = this.animation.export()
  			},
  			reset: function () {
  				this.animation.rotate(0, 0)
  					.scale(1)
  					.translate(0, 0)
  					.skew(0, 0)
  					.step({
  						duration: 0
  					})
  				this.animationData = this.animation.export()
  			}
  		}
  	}
  </script>
  
  <style>
  	.animation-element-wrapper {
  		display: flex;
  		width: 100%;
  		padding-top: 150rpx;
  		padding-bottom: 150rpx;
  		justify-content: center;
  		overflow: hidden;
  		background-color: #ffffff;
  	}
  
  	.animation-element {
  		width: 200rpx;
  		height: 200rpx;
  		background-color: #1AAD19;
  	}
  
  	.animation-buttons {
  		padding:30rpx 0;
  		width: 100%;
  		/* height: 360rpx; */
  	}
  
  	.animation-button {
  		float: left;
  		width: 44%;
  		margin: 15rpx 3%;
  	}
  
  	.animation-button-reset {
  		width: 94%;
  	}
  </style>