以下一段是向左滚动代码,如何修改每次向左滚动的距离?var Scroll = {
$:function(ele) {
var el;
if(typeof ele == 'string') el = document.getElementById(ele);
else el = ele;
if(!el) return null;
else return el;
},
//间隔滚动
gapScroll:function(objId,options) {
//定义参数
var scrollObj = Scroll.$(objId);
var contrainer = scrollObj.parentNode;
options = options || {};
var gap = parseInt(options.gap) || 2000;
var frame = parseInt(options.frame) || 20;
var distance = parseInt(options.distance) || 22;
var vate = parseFloat(options.vate) || 0.05;
var direction = options.direction || 'scrollTop';
var control = options.control || false;
var preObj = Scroll.$(options.preId) || '';
var nextObj = Scroll.$(options.nextId) || '';
var ename = options.ename || 'click';
var maxLength = Scroll.pack(scrollObj,direction);
var mark = 0,timer,gap_timer,l = Math.floor(maxLength/distance);
//启动动画
timer = setTimeout(goto,gap);
function goto() {
mark+=1;
gap_timer = setInterval(plus,frame);
}
//+动画
function plus() {
clearTimeout(timer);
var d = contrainer[direction];
if(d<mark*distance) contrainer[direction] = Math.ceil(d+(mark*distance-d)*vate);
else {
clearInterval(gap_timer);
mark = mark<l?mark:0;
contrainer[direction] = mark*distance;
timer = setTimeout(goto,gap);
}
}
//-动画
function minus() {
clearTimeout(timer);
var d = contrainer[direction];
if(d>mark*distance) contrainer[direction] = Math.floor(d-(d-mark*distance)*vate);
else {
clearInterval(gap_timer);
mark = mark<1?l:mark;
contrainer[direction] = mark*distance;
timer = setTimeout(goto,gap);
}
}
//控制部分
if(control && preObj!='' && nextObj!='') {
nextObj['on'+ename] = function() {
clearInterval(gap_timer);
mark = mark<l?mark:0;
contrainer[direction] = mark*distance;
goto();
}
preObj['on'+ename] = function() {
clearInterval(gap_timer);
mark = mark<1?l:mark;
contrainer[direction] = mark*distance;
mark-=1;
gap_timer = setInterval(minus,frame);
}
}
//鼠标事件
scrollObj.onmouseover = function() {clearTimeout(timer);}
scrollObj.onmouseout = function() {timer = setTimeout(goto,gap);}
},
//连续滚动
continuScroll:function(objId,options) {
//定义参数
var scrollObj = Scroll.$(objId);
var contrainer = scrollObj.parentNode;
options = options || {};
var frame = parseInt(options.frame) || 40;
var direction = options.direction || 'scrollTop';
var control = options.control || false;
var preObj = Scroll.$(options.preId) || '';
var nextObj = Scroll.$(options.nextId) || '';
var ename = options.ename || 'click';
var maxLength = Scroll.pack(scrollObj,direction,control);
var timer = setInterval(plus,frame);
//+动画
function plus() {
var d = contrainer[direction];
if(d<maxLength) contrainer[direction] = d+1;
else contrainer[direction] = 0;
}
//-动画
function minus() {
var d = contrainer[direction];
if(d>maxLength) contrainer[direction] = d-1;
else contrainer[direction] = 2*maxLength;
}
//控制部分
if(control && preObj!='' && nextObj!='') {
preObj['on'+ename] = function() {
clearInterval(timer);
contrainer[direction] = (contrainer[direction]>maxLength)?(contrainer[direction]-maxLength):contrainer[direction];
timer = setInterval(plus,frame);
}
nextObj['on'+ename] = function() {
clearInterval(timer);
contrainer[direction] = (contrainer[direction]<maxLength)?(contrainer[direction]+maxLength):contrainer[direction];
timer = setInterval(minus,frame);
}
}
//鼠标事件
scrollObj.onmouseover = function() {clearInterval(timer);}
scrollObj.onmouseout = function() {
timer =(contrainer[direction]<maxLength)?setInterval(plus,frame):setInterval(minus,frame);
}
},
//重包裹内容,返回最大宽度或高度
pack:function(obj,type,control) {
var temp = obj.innerHTML;
obj.innerHTML = '';
var span = document.createElement('span');
obj.appendChild(span);
span.innerHTML = temp;
span.style.styleFloat = 'left';
span.style.cssFloat = 'left';
var len = (type == 'scrollTop')?span.offsetHeight:span.offsetWidth;
span.innerHTML+=temp;
if(typeof control !='undefined' && control == true) span.innerHTML+=temp;
return len;
}
};
添加回答
举报
0/150
提交
取消