ranking.js
2.62 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
function newScoll(container, options){
if (!container) return;
options = options || {};
var actions = new Object();
var pre = options.pre, //后退按钮
next = options.next,//前进按钮
moveWidth = options.moveWidth ? options.moveWidth : 0,//每次滚动的距离
maxWidth = options.maxWidth ? options.maxWidth : 0,//容器的最大宽度
changeWidth = options.changeWidth,//浏览器的临界宽度
maxMoveWidth = options.maxMoveWidth,
minMoveWidth = options.minMoveWidth,
actionCode = 0,//防止连续点击
end = false;
//后退按钮
pre.bind('click',function(){
if(actionCode == 1){
return false;
}
if(parseInt(container.css('left'))<0){//如果容器的左边有位移
actionCode = 1;
var left = parseInt(container.css('left'));
actions.scoll(actions.getNewLeft(left,'+'));
}
});
//前进按钮
next.bind('click', function () {
if(actionCode == 1){
return false;
}
if(actions.checkEnd()){//如果没有滚动到最后,则可以继续往下滚动
actionCode = 1;
var left = parseInt(container.css('left'));
actions.scoll(actions.getNewLeft(left,'-'));
}
});
//判断是否到最后
actions.checkEnd = function(){
var left = parseInt(container.css('left'));
if(-(left-moveWidth)>=maxWidth){
end = true;
return false;
}else{
end = false;
return true;
}
};
//图片滚动
actions.scoll = function(newLeft){
container.stop(true, false).animate({ "left": newLeft }, 600, function(){
actions.setAstyle();
actionCode = 0;
});
};
//获得新的偏移量
actions.getNewLeft = function(left,style){
if(style=='-'){
if(-(left-moveWidth)>(maxWidth-moveWidth)){
var nowLeft = -(maxWidth-moveWidth);
}else{
var nowLeft = left - moveWidth;
}
}else{
if(-left<moveWidth || -left==0){
var nowLeft=0
}else{
var nowLeft = left + moveWidth;
}
}
return nowLeft;
};
//改变箭头样式
actions.setAstyle = function(){
parseInt(container.css('left'))==0? pre.addClass('off') : pre.removeClass('off');
actions.checkEnd() ? next.removeClass('off') : next.addClass('off');
};
//窗口改变初始化各种参数
$(window).bind('resize',function(){
var winwidth = parseInt($(window).width());
var left = parseInt(container.css('left'));
if (winwidth>changeWidth){
moveWidth=maxMoveWidth;
}else{
moveWidth=minMoveWidth;
}
if(end==true){
actions.scoll(-(maxWidth-moveWidth));
}
if(parseInt(container.css('left'))==0){
actions.scoll(0);
}
actions.setAstyle();
})
}