Fader_wev8.js
1.49 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
Fader = function (config) {
this.element = config.element;
this.elementID = config.elementID;
this.style = config.style;
this.num = config.num;
this.maxMove = config.maxMove;
this.finishNum = "string";
this.interval = config.interval || 10;
this.step = config.step || 20;
this.onFinish = config.onFinish;
this.isFinish = false;
this.timer = null;
this.method = this.num >= 0;
this.c = this.elementID ? $("#" + this.elementID) : this.element;
this.run = function () {
clearInterval(this.timer);
this.fade();
if (this.isFinish) {
this.onFinish && this.onFinish();
} else {
var f = this;
this.timer = setInterval(function () {
f.run();
}, this.interval);
}
};
this.fade = function () {
if (this.finishNum == "string") {
this.finishNum = (parseInt(this.c.css(this.style)) || 0) + this.num;
}
var a = parseInt(this.c.css(this.style)) || 0;
if (this.finishNum > a && this.method) {
a += this.step;
if (a >= 0) {
this.finishNum = a = 0;
}
} else {
if (this.finishNum < a && !this.method) {
a -= this.step;
if (a * -1 >= this.maxMove) {
this.finishNum = a = this.maxMove * -1;
}
}
}
if (this.finishNum <= a && this.method || this.finishNum >= a && !this.method) {
this.c.css(this.style, this.finishNum + "px");
this.isFinish = true;
this.finishNum = "string";
} else {
this.c.css(this.style, a + "px");
}
};
};