-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmotionCube.js
More file actions
927 lines (733 loc) · 26.1 KB
/
motionCube.js
File metadata and controls
927 lines (733 loc) · 26.1 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
;(function(){
// 模块管理器
function require(n) {
var module = require.modules[n];
if(!module){ throw new Error("module "+n+" is not exist!")}
if(!module["exports"]){
module.exports = {};
module.define.call(module,module,module.exports);
delete module.define
}
return module.exports
}
require.modules = {};
require.register = function (n,fn) {
this.modules[n] = {};
this.modules[n].define = fn
};
/*
* 浏览器是否支持transform属性和是否有前缀
*
* @exports {string} transform属性名称
* */
require.register("transformTest",function (module,exports) {
var styles = [
'webkitTransform',
'MozTransform',
'msTransform',
'OTransform',
'transform'
];
var target = getComputedStyle(document.createElement("div"));
var style;
for(var i = 0;i<styles.length;i++){
if(styles[i] in target){
style = styles[i];
break
}
}
module.exports = style == undefined?false:style
});
/*
* 浏览器是否支持transition3d动画
*
* @exports {boolean} 是否支持3d
* */
require.register("threeDTest",function (module,exports) {
/*依赖模块*/
var transformTest = require("transformTest");
var result;
if(transformTest){
var target = document.createElement("div");
document.body.appendChild(target);
target.style[transformTest] = "translate3d(1px,1px,1px)";
var threeDTest = getComputedStyle(target)[transformTest];
if(threeDTest!="none"){
result = true;
} else {
result = false
}
} else {
result = false
}
module.exports = result
});
/*
* 浏览器是否支持transition属性和是否有前缀
*
* @exports {string} transition属性名称
* */
require.register("transitionTest",function (module,exports) {
var styles = [
'webkitTransition',
'MozTransition',
'msTransition',
'OTransition',
'transition'
];
var target = getComputedStyle(document.createElement("div"));
var style;
for(var i = 0;i<styles.length;i++){
if(styles[i] in target){
style = styles[i];
break
}
}
module.exports = style == undefined?false:style
});
/*
* 浏览器是否完全支持transition动画效果
*
* @exports {boolean} 是否完全支持动画
* */
require.register("testResult",function (module,exports) {
/*依赖模块*/
var first= require("transformTest"),
second = require("threeDTest"),
third = require("transitionTest");
module.exports = first && second && third
});
/*
* 浏览器的transitionEnd事件和前缀
*
* @exports {string} transitionEnd事件名称
* */
require.register("endEvent",function (module,exports) {
var transitionTest = require("transitionTest");
var events = {
webkitTransition:"webkitTransitionEnd",
MozTransition:"MozTransitionEnd",
msTransition:"transitionend",
OTransition:"OTransitionEnd",
transition:"transitionend"
};
module.exports = events[transitionTest]
});
/*
* transform矩阵设置函数库
*
* @exports {object,function} 包含矩阵设置函数的对象
* @param {number} transform设置参数
* @return {object} 矩阵
* @api {private}
* */
require.register("matrixLibrary",function (module,exports) {
module.exports = {
translateAll: function (x, y, z) {
return [1,0,0,0,0,1,0,0,0,0,1,0,x,y?y:0,z?z:0,1]
},
translateX: function (x) {
return [1,0,0,0,0,1,0,0,0,0,1,0,x,0,0,1]
},
translateY: function (y) {
return [1,0,0,0,0,1,0,0,0,0,1,0,0,y,0,1]
},
translateZ: function (z) {
return [1,0,0,0,0,1,0,0,0,0,1,0,0,0,z,1]
},
scale: function (x, y, z) {
return [x,0,0,0,0,y?y:1,0,0,0,0,z?z:1,0,0,0,0,1]
},
scaleX: function (x) {
return [x,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
},
scaleY: function (y) {
return [1,0,0,0,0,y,0,0,0,0,1,0,0,0,0,1]
},
scaleZ: function (z) {
return [1,0,0,0,0,1,0,0,0,0,z,0,0,0,0,1]
},
rotate: function (x, y, z, deg) {
var sin = Math.sin(Math.PI / (180 / deg)),
cos = Math.cos(Math.PI / (180 / deg)),
norm = Math.sqrt(x * x + y * y + z * z);
var nx = x / norm,
ny = x / norm,
nz = z / norm;
return [
nx*nx*(1-cos)+cos,nx*ny*(1-cos)+nz*sin,nx*nz*(1-cos)-ny*sin,0,
nx*ny*(1-cos)-nz*sin,ny*ny*(1-cos)+cos,ny*nz*(1-cos)+nx*sin,0,
nx*nz*(1-cos)+ ny*sin,ny*nz*(1-cos)-nx*sin,nz*nz*(1-cos)+cos,0,
0,0,0,1]
},
rotateX: function (deg) {
var sin = Math.sin(Math.PI / (180 / deg)),
cos = Math.cos(Math.PI / (180 / deg));
return [1,0,0,0,0,cos,sin,0,0,-sin,cos,0,0,0,0,1]
},
rotateY: function (deg) {
var sin = Math.sin(Math.PI / (180 / deg)),
cos = Math.cos(Math.PI / (180 / deg));
return [cos,0,-sin,0,0,1,0,0,sin,0,cos,0,0,0,0,1]
},
rotateZ: function (deg) {
var sin = Math.sin(Math.PI / (180 / deg)),
cos = Math.cos(Math.PI / (180 / deg));
return [cos,sin,0,0,-sin,cos,0,0,0,0,1,0,0,0,0,1]
},
skew: function (x, y) {
return [
1,y?Math.tan(Math.PI/(180/y)):Math.tan(Math.PI/(180/x)),0,0,
Math.tan(Math.PI/(180/x)),1,0,0,
0,0,1,0,
0,0,0,1]
},
skewX: function (x) {
return [1,0,0,0,Math.tan(Math.PI/(180/x)),1,0,0,0,0,1,0,0,0,0,1]
},
skewY: function (y) {
return [1,Math.tan(Math.PI/(180/y)),0,0,0,1,0,0,0,0,1,0,0,0,0,1]
}
}
});
/*
* 两个三阶矩阵相乘的函数
*
* @exports {function} 矩阵组合函数
* @ param {object} 矩阵
* @ return {object} 矩阵
* @ api {private}
* */
require.register("matrixCombine",function (module,exports) {
module.exports = function (a1,a2) {
return [
a1[0]*a2[0]+a1[4]*a2[1]+a1[8]*a2[2]+a1[12]*a2[3],
a1[1]*a2[0]+a1[5]*a2[1]+a1[9]*a2[2]+a1[13]*a2[3],
a1[2]*a2[0]+a1[6]*a2[1]+a1[10]*a2[2]+a1[14]*a2[3],
a1[3]*a2[0]+a1[7]*a2[1]+a1[11]*a2[2]+a1[15]*a2[3],
a1[0]*a2[4]+a1[4]*a2[5]+a1[8]*a2[6]+a1[12]*a2[7],
a1[1]*a2[4]+a1[5]*a2[5]+a1[9]*a2[6]+a1[13]*a2[7],
a1[2]*a2[4]+a1[6]*a2[5]+a1[10]*a2[6]+a1[14]*a2[7],
a1[3]*a2[4]+a1[7]*a2[5]+a1[11]*a2[6]+a1[15]*a2[7],
a1[0]*a2[8]+a1[4]*a2[9]+a1[8]*a2[10]+a1[12]*a2[11],
a1[1]*a2[8]+a1[5]*a2[9]+a1[9]*a2[10]+a1[13]*a2[11],
a1[2]*a2[8]+a1[6]*a2[9]+a1[10]*a2[10]+a1[14]*a2[11],
a1[3]*a2[8]+a1[7]*a2[9]+a1[11]*a2[10]+a1[15]*a2[11],
a1[0]*a2[12]+a1[4]*a2[13]+a1[8]*a2[14]+a1[12]*a2[15],
a1[1]*a2[12]+a1[5]*a2[13]+a1[9]*a2[14]+a1[13]*a2[15],
a1[2]*a2[12]+a1[6]*a2[13]+a1[10]*a2[14]+a1[14]*a2[15],
a1[3]*a2[12]+a1[7]*a2[13]+a1[11]*a2[14]+a1[15]*a2[15]
]
}
});
/*
* 字符转化矩阵函数
*
* @exports {function} 转化函数
* @ param {string} transform的matrix或者matrix3d值
* @ return {object} 矩阵
* @ api {private}
* */
require.register("stringToMatrix",function (module,exports) {
module.exports = function (t) {
if(t == "none"){
return [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
} else {
var i = t.indexOf("3d")<0?7:9;
var m = t.substring(i,t.length-1);
m = m.split(",");
for(var i = 0;i<m.length;i++){
m[i] = parseFloat(m[i])
}
if(m.length==6){
return [m[0],m[1],0,0,m[2],m[3],0,0,0,0,1,0,m[4],m[5],0,1]
} else {
return [
m[0],m[1],m[2],m[3],
m[4],m[5],m[6],m[7],
m[8],m[9],m[10],m[11],
m[12],m[13],m[14],m[15]]
}
}
}
});
/*
* 矩阵字符转化函数
*
* @exports {function} 转化函数
* @ param {object} 矩阵
* @ return {string} transform的matrix或者matrix3d值
* @ api {private}
* */
require.register("matrixToString",function (module,exports) {
module.exports = function (m) {
return "matrix3d("+m.join(",")+")"
}
});
/*
* 贝塞尔曲线
*
* @exports {function} 贝塞尔曲线函数
* @ param {string,array} 贝塞尔曲线默认值或者曲线数组
* @ return {string} transitionTimingFunction值
* @ api {private}
* */
require.register("cubicBezier",function (module,exports) {
module.exports = function (f) {
if(typeof f == "string"){
return f
}
return "cubic-bezier("+f.join(",")+")"
}
});
/*
* style设置函数
*
* @exports {function} style设置函数
* @ param {object} 贝塞尔曲线默认值或者曲线数组
* @ api {private}
* */
require.register("styleSet",function (module,exports) {
module.exports = function (o) {
for(var k in o){
if(this.style[k] != o[k]){
this.style[k] = o[k]
}
}
}
});
/*
* 属性赋值函数
*
* @exports {function} 属性赋值函数
* @ param {object} 传授属性的对象和被传授的对象
* @ api {private}
* */
require.register("extendProperty",function (module,exports) {
module.exports = function (target,giver) {
for(var k in giver){
if(!target[k]){
target[k] = giver[k]
}
}
}
});
/*
* 事件管理器
*
* @exports {object,function} 属性赋值函数
* @ param {object,string,function} 设置发射器的对象,事件名称,回调函数等
* @ api {private}
* */
require.register("eventBank",function (module,exports) {
module.exports = {
addAction:function(event,func){
var eventBank = this._bank || (this._bank = {}),
bankCase = eventBank[event] || (eventBank[event] = []);
bankCase.push(func)
},
trigger:function(event){
var args = Array.prototype.slice.call(arguments,1);
var eventBank = this._bank,bankCase;
if(!eventBank|| !(bankCase=eventBank[event])) return;
for(var i = 0;i<bankCase.length;i++){
return bankCase[i].apply(this,args)
}
}
}
});
/*
* 事件监听封装
*
* @exports {object,function} 浏览器事件监听器的封装函数
* @param {element,string,function,boolean} 设置监听器的对象,事件名称,回调函数等
* @ api {private}
* */
require.register("eventTools",function (module,exports) {
var add = window.addEventListener?"addEventListener":"attachEvent",
sub = window.removeEventListener?"removeEventListener":"detachEvent",
header = add == "attachEvent"?"on":"";
exports.add = function (el,eName,fn,catcher) {
el[add](header+eName,fn,catcher || false)
};
exports.sub = function (el,eName,fn,catcher) {
el[sub](header+eName,fn,catcher || false)
}
});
// 主程序
require.register("motion",function (module,exports) {
/* 依赖模块 */
var tf = require("transformTest"), //transform名称
ts = require("transitionTest"), //transition名称
tr = require("testResult"), //动画支持结果
endE = require("endEvent"), //transitionEnd事件名称
ml = require("matrixLibrary"), //transform矩阵函数库
mc = require("matrixCombine"), //矩阵结合函数
mts = require("matrixToString"), //矩阵转字符函数
stm = require("stringToMatrix"), //字符转矩阵函数
ep = require("extendProperty"), //属性复制函数
eb = require("eventBank"), //事件管理器
ss = require("styleSet"), //style设置函数
cb = require("cubicBezier"), //贝塞尔曲线函数
et = require("eventTools"); //事件监听器封装
/* 支持检测 */
if(!tr){
alert("您的浏览器版本过低,动画效果可能无法正常展现!")
}
//motion对象构造函数
function Motion(target) {
this.el = target;
this._init();
return this
}
Motion.prototype = {
//动画用于设置matrix矩阵的方法,包含transform的所有过渡效果
translateAll:function (x,y,z) {
return this.trigger("matrixSet","translateAll",x,y,z)
},
translateX:function (x) {
return this.trigger("matrixSet","translateX",x)
},
translateY:function (y) {
return this.trigger("matrixSet","translateY",y)
},
translateZ:function (z) {
return this.trigger("matrixSet","translateZ",z)
},
scale:function (x,y,z) {
return this.trigger("matrixSet","scale",x,y,z)
},
scaleX:function (x) {
return this.trigger("matrixSet","scaleX",x)
},
scaleY:function (y) {
return this.trigger("matrixSet","scaleY",y)
},
scaleZ:function (z) {
return this.trigger("matrixSet","scaleZ",z)
},
rotate:function (x,y,z,deg) {
return this.trigger("matrixSet","rotate",x,y,z,deg)
},
rotateX:function (x) {
return this.trigger("matrixSet","rotateX",x)
},
rotateY:function (y) {
return this.trigger("matrixSet","rotateY",y)
},
rotateZ:function (z) {
return this.trigger("matrixSet","rotateZ",z)
},
skew:function (x,y) {
return this.trigger("matrixSet","skew",x,y)
},
skewX:function (x) {
return this.trigger("matrixSet","skewX",x)
},
skewY:function (y) {
return this.trigger("matrixSet","skewY",y)
},
//motion对象api
_init:function () {
this.trigger("initElement")
},
newFrame:function (t,f) {
return this.trigger("newFrame",t,f)
},
newAttribute:function (n,v) {
return this.trigger("newAttribute",n,v)
},
prepare:function () {
return this.trigger("prepare")
},
move:function (i,d,f) {
return this.trigger("move",i,d,f)
},
loop:function (i,f) {
return this.trigger("loop",i,f)
},
stop:function (f) {
this.trigger("stop",f)
},
reset:function (i) {
return this.trigger("reset",i)
}
};
ep(Motion.prototype,eb);
/*
* motion初始化事件
* 新建一个对象,包含动画的对象元素,关键帧储存器,还有各种状态属性设置;
* */
Motion.prototype.addAction("initElement",function () {
this.direction = "forward";
this.status = "stop";
this.endCount = 0;
this.motionCount = 0;
this.keyFrames = [{}];
this.moveFrame = this.keyFrames[0];
this.moveFrame[tf] = getComputedStyle(this.el)[tf];
});
/*
* motion新建关键帧事件
* 给motion对象新建一个关键帧,并设置该帧与前帧之间的运动时间和运动曲线
*
* @ param1 {number} transitionDuration
* @ param2 {string,array} transitionTimingFunction
* @ api {public}
* */
Motion.prototype.addAction("newFrame",function (t,f) {
if(this.status == "moving" ){
return false
} else {
this.status = "setting"
}
var k = this.keyFrames,
i = k.length;
k[i] = {};
k[i+1] = {};
k[i][ts+"Property"] = "all";
k[i][ts+"Duration"] = t?t+"ms" :this.el.style[ts+"Duration"] || "1000ms";
k[i][ts+"TimingFunction"] = f?cb(f):this.el.style[ts+"TimingFunction"] || "linear";
Object.defineProperty(k[i],"eventCount",{
numerable:false,
writable:true,
value:0
});
if(k[i-1]){
for(var key in k[i-1]){
k[i+1][key] = k[i-1][key]
}
}
return this
});
/*
* motion关键帧矩阵设置事件
* 调用transform矩阵函数库,用于设置关键帧矩阵
* 传入函数为调用的函数名称,传入函数的参数
*
* @ param1 {string} 矩阵函数名称
* @ param2 {number} 传入矩阵函数的参数
* @ api {public}
* */
Motion.prototype.addAction("matrixSet",function () {
if(this.status == "setting"){
var k = this.keyFrames,
i = k.length-1,
n = Array.prototype.shift.call(arguments,0);
var om = stm(k[i][tf]);
var nm = ml[n].apply(null,arguments);
k[i][tf] = mts(mc(om,nm));
return this
}
return false
});
/*
* motion关键帧其它属性设置事件
* 设置目标元素除transform外其它属性值
* 传入属性名称和值
*
* @ param1 {string} 属性名称
* @ param2 {string} 属性值
* @ api {public}
* */
Motion.prototype.addAction("newAttribute",function (n,v) {
if(this.status == "setting"){
var k = this.keyFrames;
k[k.length-1][n] = v;
for(var i =k.length-3;i>=0;i-=2){
if(!k[i][n]){
k[i][n] = ""
}
}
return this
}
return false
});
/*
* motion动画循环播放时间
* 让元素所以关键帧动画循环播放
*
* @ param1 {number} 循环次数
* @ param2 {function} 循环完成后的回调函数
* @ api {public}
* */
Motion.prototype.addAction("loop",function (i,f) {
if(i == 0){
this.motionCount = NaN
} else {
this.motionCount = i?i*(((this.keyFrames.length-1)/2+1)*2-2):0.5*(((this.keyFrames.length-1)/2+1)*2-2)
}
this.trigger("motionMove",f)
});
/*
* motion单帧播放时间
* 让元素只播放一个关键帧的动画
*
* @ param1 {number} 动画运动帧数
* @ param1 {string} 动画运动方向
* @ param1 {function} 动画完成或的回调函数
* @ api {public}
* */
Motion.prototype.addAction("move",function (i,d,f) {
this.motionCount = i;
if(d && d != null){
this.direction = d
}
this.trigger("motionMove",f)
});
/*
* motion预备事件
* motion对象同级所有帧之间过渡需要触发的transitionEnd事件数并且记录
*
* @ api {public}
* */
Motion.prototype.addAction("prepare",function () {
if(this.status == "setting"){
this.status = "prepare";
var k = this.keyFrames;
for(var i = 1;i<this.keyFrames.length;i+=2){
for(var key in k[i-1]){
if(k[i-1][key] != k[i+1][key]){
k[i].eventCount++
}
}
}
return this
}
return false
});
/*
* motion方向检测事件
* 检测动画是否需要转换播放方向并且设定方向
*
* @ api {private}
* */
Motion.prototype.addAction("directionTest",function () {
var k = this.keyFrames,
o = this.moveFrame,
i = k.indexOf(o);
if(i == 0){
this.direction = "forward"
} else if(i == k.length-1){
this.direction = "backward"
}
});
/*
* motion关键帧检测事件
* 检测动画的播放帧和过渡帧
*
* @ api {private}
* */
Motion.prototype.addAction("frameTest",function () {
var i = this.keyFrames.indexOf(this.moveFrame);
if(this.direction == "forward"){
this.transFrame = this.keyFrames[i+1];
this.moveFrame = this.keyFrames[i+2]
} else {
this.transFrame = this.keyFrames[i-1];
this.moveFrame = this.keyFrames[i-2]
}
if(!this.moveFrame || !this.transFrame){
this.motionCount = 0;
return
}
});
/*
* motion帧运动时间
* 读取motion对象的播放帧和过渡帧并且赋值给目标元素以触发动画效果
*
* @ api {private}
* */
Motion.prototype.addAction("frameRun",function () {
ss.call(this.el,this.transFrame);
ss.call(this.el,this.moveFrame)
});
/*
* motion停止事件
* 让动画停止播放,并且重置部分属性
*
* @ param {string} 动画停止后的播放方向
* @ api {public}
* */
Motion.prototype.addAction("stop",function (f) {
et.sub(this.el,endE,this.endEvent,false);
this.endEvent = null;
this.el.style[ts+"Duration"] = "0ms";
this.status = "prepare";
ss.call(this.el,this.moveFrame);
this.motionCount = 0;
if(f){
f()
}
return this
});
/*
* motion重置事件
* 让动画停止在选定的关键帧状态,并且重置所有motion属性
*
* @ param {number} 动画停止的关键帧下标
* @ api {public}
* */
Motion.prototype.addAction("reset",function (n) {
et.sub(this.el,endE,this.endEvent,false);
this.endEvent = null;
this.el.style[ts+"Duration"] = "0ms";
this.status = "stop";
this.direction = "forward";
this.motionCount = 0;
this.keyFrames = [this.keyFrames[n*2-2] || this.moveFrame];
this.moveFrame = this.keyFrames[0];
this.transFrame = {};
for( var k in this.moveFrame){
if(this.moveFrame[k] == ""){
delete this.moveFrame[k]
} else if(this.el.style[k] != this.moveFrame[k]) {
this.el.style[k] = this.moveFrame[k]
}
}
return this
});
/*
* motion移动事件
*
* @param {function} 回调函数
*
* */
Motion.prototype.addAction("motionMove",function (f) {
if(this.status == "prepare"){
this.status = "moving";
this.endEvent = this.trigger("motionEnd",f).bind(this);
et.add(this.el,endE,this.endEvent,false);
this.trigger("directionTest");
this.trigger("frameTest");
this.trigger("frameRun");
}
});
/*
* motion动画完成事件
* 设定动画每次transitionEnd后的动作和触发回调函数
*
* @ param {function} 回调函数
* @ api {private}
* */
Motion.prototype.addAction("motionEnd",function (f) {
return function () {
this.endCount++;
if(this.transFrame.eventCount==this.endCount){
this.endCount = 0;
this.motionCount--;
if(this.motionCount == 0){
return this.trigger("stop",f)
} else {
this.trigger("directionTest");
this.trigger("frameTest");
this.trigger("frameRun");
}
}
}
});
module.exports = Motion
});
window.Motion = require("motion")
})();
console.log('test')