movemove.js
2.35 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
define(function(require, exports, module) {
var movemove = function(target, options){
var opt = $.extend({
name: {
box: 'listbox',
inner: 'ul',
child: 'li'
},
moveType: 2,
interval: 3000
}, options);
var ne = opt.name, clock, animate;
function _init(){
var doms = getDoms();
var cache = [_shiftArray(doms.li, 2), doms.li];
//If the childnode's number less than six, we stop the action.
if (cache[1].length < 6)return false;
opt.moveType == 1 ? animate = _anone : animate = _antwo;
animate( doms, cache );
};
function _anone( doms, cache ){
clock = setInterval(function(){
doms.ul.animate(
{'top': -$(doms.li).height()},
300,
function(){
$(this).removeAttr('style');
for (var i = 0, l = cache.length; i < l; i++){
$(cache[0][i]).remove().appendTo($(this));
}
cache = _change(cache);
}
);
}, opt.interval);
};
function _antwo( doms, cache ){
var t = 0;
clock = setInterval(function(){
doms.ul.css({
'top': t-=1
});
if (t == -30){
doms.ul.removeAttr('style');
t = 0;
for (var i = 0, l = cache.length; i < l; i++){
$(cache[0][i]).remove().appendTo(doms.ul);
}
cache = _change(cache);
}
}, 50);
};
function _clear(){
clearInterval( clock );
};
function getDoms(){
var box = $('.'+ ne.box);
return {
box: box,
ul : box.find(ne.inner),
li : box.find(ne.child)
}
};
/*
* Slice the Array with the param(shiftNumber),
* And return an array with shiftNumber length;
* @param {array, number}
* @return {array}
*/
function _shiftArray(array, shiftNumber){
var cache = [];
for ( var i = 0; i < shiftNumber; i++ ){
cache.push( _shift(array) );
};
return cache;
};
/*
* @param {array([],[])}
* @return {variable}
*/
function _change(arr){
for ( var i = 0, l = arr[0].length; i < l; i++ ){
_push( arr[0], _shift(arr[1]) );
_push( arr[1], _shift(arr[0]) );
};
return arr;
};
function _shift(arr){
return Array.prototype.shift.call(arr);
};
function _push(arr, elem){
return Array.prototype.push.call(arr, elem);
};
return {
init: _init,
clear: _clear
}
};
return movemove;
});