Repository navigation
Expand file tree
/
Copy pathtext-moveFrame.html
More file actions
110 lines (101 loc) · 2.85 KB
/
Copy pathtext-moveFrame.html
File metadata and controls
110 lines (101 loc) · 2.85 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
<style type="text/css" media="screen">
#div1{
width: 500px;
height: 500px;
background: red;
}
</style>
<script src="jspackage.js" type="text/javascript" charset="utf-8"></script>
<script src="Tween.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
window.onload=function(){
var oDiv = document.getElementById('div1');
//obj为目标dom节点,attrobj为操作属性键值对,dur为设定运行时间,fn为设定运动方式
function myAnimate(obj,attrobj,dur,fn,callback){
q.queue(function(){
var tween;
var callfn;
if (arguments.length>=4) {
// 由于传入参数数量未知,通过判断选择,Tween方法的参数为4或者大于4,符合条件则存在Tween方法(参数fn),把fn赋予tween,否则则说明使用默认tween,fn为回调函数
if (fn.length>=4) {
tween = fn;
callfn = null;
}else{
tween = Tween.Quad.easeIn;
callfn = fn;
}
}else{
tween = fn?fn: Tween.Quad.easeIn;
callback = callback?callback:null;
}
var start = [];
var change = [];
var times = 0;
for (var i in attrobj) {
start[i] = css(obj,i);
change[i] = attrobj[i]-start[i];
};
obj.timer = setInterval(function(){
var stop = true;
if (times<dur) {
stop = false;
for (var i in attrobj) {
css(obj,i,tween(times,start[i],change[i],dur))
};
};
times += 60;
if (stop) {
for (var i in attrobj) {
css(obj,i,attrobj[i]);
};
clearInterval(obj.timer);
if (callfn) {
callfn()
};
q.dequeue();
};
},60);
});
}
function Queue(){
this.list=[];
}
Queue.prototype={
queue:function(fn){
this.list.push(fn);
// 为了让队列自动执行,给list列表一个标记mark,当list的第一位不为mark的时候,让队列执行
if (this.list[0] != 'mark') {
this.dequeue();
};
return this;
},
dequeue:function(){
var fn = this.list.shift();
if (fn=='mark') {
fn = this.list.shift();
};
if (fn) {
this.list.unshift('mark');
fn();
};
}
}
var q = new Queue();
myAnimate(oDiv,{width:100,height:100},600);
myAnimate(oDiv,{width:700,height:100},1600);
myAnimate(oDiv,{width:700,height:740},800);
myAnimate(oDiv,{width:700,height:700},600)
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>