forked from apache/incubator-weex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation.we
143 lines (137 loc) · 4.48 KB
/
animation.we
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<template>
<div>
<wxc-panel title="Transform" type="primary">
<wxc-button value="Rotate" onclick="{{rotate}}" type="primary" size="middle"></wxc-button>
<wxc-button value="Scale" onclick="{{scale}}" type="primary" size="middle" style="margin-top:12px;"></wxc-button>
<wxc-button value="Translate" onclick="{{translate}}" type="primary" size="middle"
style="margin-top:12px;"></wxc-button>
<wxc-button value="Transform" onclick="{{transform}}" type="success" size="middle"
style="margin-top:12px;"></wxc-button>
</wxc-panel>
<wxc-panel title="Others" type="primary">
<wxc-button value="BgColor" onclick="{{color}}" type="primary" size="middle"></wxc-button>
<wxc-button value="Opacity" onclick="{{opacity}}" type="primary" size="middle"
style="margin-top:12px;"></wxc-button>
<wxc-button value="All" onclick="{{composite}}" type="success" size="middle" style="margin-top:12px;"></wxc-button>
</wxc-panel>
<div id="block" class="block" style="transform-origin:{{transformOrigin}}">
<text class="block-txt">Anim</text>
</div>
</div>
</template>
<script>
require('weex-components');
module.exports = {
data: {
transformOrigin: 'center center',
current_rotate: 0,
current_scale: 1,
current_color: '#FF0000',
current_opacity: 1,
current_translate: '',
current_transform: '',
isStop: true
},
methods: {
anim: function(styles, timingFunction, duration, callback) {
this.$call('animation', 'transition', this._ids.block.el.ref, {
styles: styles,
timingFunction: timingFunction,
duration: duration
}, callback);
},
rotate: function() {
var self = this;
self.current_rotate += 90;
self.anim({
transform: 'rotate(' + self.current_rotate + 'deg)'
}, 'ease-in-out', 500, function() {
if (self.current_rotate === 360) {
self.current_rotate = 0;
}
else {
self.rotate();
}
});
},
translate: function() {
this.current_translate = this.current_translate ? '' : 'translate(50%, 50%)';
this.anim({
transform: this.current_translate
}, 'ease-in', 500, function() {
});
},
scale: function() {
var self = this;
self.current_scale = self.current_scale === 2 ? .5 : 2
self.anim({
transform: 'scale(' + self.current_scale + ')'
}, 'linear', 500, function() {
});
},
transform: function() {
var self = this;
this.current_transform = this.current_transform ? '' : 'rotate(45deg) scale(1.5)';
this.anim({
transform: this.current_transform,
transformOrigin: 'left top'
}, 'ease-out', 500, function() {
if (self.current_transform !== '') {
self.anim({
transform: 'rotate(-90deg) scale(1.2)',
transformOrigin: 'left top'
}, 'ease-out', 500, function() {
})
}
else {
}
});
},
composite: function() {
var self = this;
self.current_transform = self.current_transform ? '' : 'rotate(45deg) scale(1.5) translate(50%, 50%)';
self.current_color = self.current_color === '#F0AD4E' ? '#D9534F' : '#F0AD4E';
self.current_opacity = self.current_opacity === 1 ? 0.1 : 1;
this.anim({
transform: this.current_transform,
transformOrigin: 'left top',
backgroundColor: self.current_color,
opacity: self.current_opacity
}, 'ease-out', 1000, function() {
});
},
color: function() {
var self = this;
self.current_color = self.current_color === '#F0AD4E' ? '#D9534F' : '#F0AD4E';
self.anim({
backgroundColor: self.current_color
}, 'linear', 500, function() {
});
},
opacity: function() {
var self = this;
self.current_opacity = self.current_opacity === 1 ? 0.1 : 1;
self.anim({
opacity: self.current_opacity
}, 'linear', 500, function() {
});
}
}
};
</script>
<style>
.block {
position: absolute;
width: 250px;
height: 250px;
top: 300px;
left: 400px;
background-color: #F0AD4E;
align-items: center;
justify-content: center;
}
.block-txt {
color: #FFFFFF;
font-size: 70px;
}
</style>