-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
121 lines (110 loc) · 3.39 KB
/
script.js
File metadata and controls
121 lines (110 loc) · 3.39 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
window.onload = init;
var FUIT = {};
function init() {
FUIT.carousel.init({
interval: 4000
});
}
FUIT.carousel = (function() {
var obj,
that = {},
interval,
loop,
step,
count,
t;
that.init = function(props) {
if (typeof(props) === 'undefined') {
return;
}
if (typeof(props.target) === 'undefined') {
if(!FUIT.util.getByClassName('carousel').length) {
return;
}
}
interval = 'interval' in props ? props.interval : 4000;
obj = props.target || FUIT.util.getByClassName('carousel')[0];
step = FUIT.util.width(obj);
count = FUIT.util.children(obj).length;
t = setTimeout(that.slide, interval);
};
that.slide = function() {
to = (FUIT.util.left(obj) - step) % (step * count);
FUIT.util.animate(obj, 'left', to);
t = setTimeout(that.slide, interval);
};
that.getTarget = function () {
return obj;
};
return that;
})();
FUIT.util = {
getByClassName: function(classList, node) {
node = node || document;
if(document.getElementsByClassName) {
return node.getElementsByClassName(classList);
} else {
var list = node.getElementsByTagName('*'),
length = list.length,
classArray = classList.split(/\s+/),
classes = classArray.length,
result = [],
i,
j;
for(i = 0; i < length; i++) {
for(j = 0; j < classes; j++) {
if(list[i].className.search('\\b' + classArray[j] + '\\b') != -1) {
result.push(list[i]);
break;
}
}
}
return result;
}
},
width: function(el) {
if(window.getComputedStyle) {
return parseInt(window.getComputedStyle(el, null).width, 10);
} else {
return parseInt(el.currentStyle('width', null), 10);
}
},
left: function(el) {
if(window.getComputedStyle) {
return parseInt(window.getComputedStyle(el, null).left, 10) || 0;
} else {
return parseInt(el.currentStyle('left', null), 10) || 0;
}
},
children: function(el) {
var children = [],
childNodes = el.childNodes;
for (var i=0, l = childNodes.length; i < l; i++) {
if (childNodes[i].nodeType !== 3 && childNodes[i].nodeType !== 8) {
children.push(childNodes[i]);
}
}
return children;
},
animate: function(obj, prop, value) {
var step = FUIT.util.left(obj) >= value ? -100 : 100,
before = new Date(),
now,
delay = 50,
elapsedTime;
function go() {
now = new Date();
elapsedTime = now.getTime() - before.getTime();
if (elapsedTime < delay * 5) {
if(Math.abs(FUIT.util.left(obj) - value)) {
obj.style[prop] = (FUIT.util.left(obj) + step) + 'px';
setTimeout(arguments.callee, delay);
}
} else {
obj.style[prop] = value + "px";
}
before = new Date();
}
go();
}
};