/*
间歇式无缝滚动
http://code.ciaoca.cn/
日期:2011-11-16
direction 参数说明
-----
left:自左向右
right:自右向左
top:自上向下
bottom:自下向上
settings 参数说明
-----
step:滚动步长
speed:滚动速度
time:自动滚动间隔时间
auto:是否自动滚动
plus:是否使用plus按钮
minus:是否使用minus按钮
------------------------------ */
(function($){
$.fn.scrollshow=function(direction,settings){
if(this.length<1){return;};
// 默认值
settings=$.extend({
step:1,//滚动图片数
speed:500,//滚动速度
time:3000,//间隔时间
auto:true,
plus:true,
minus:true
},settings);
var scroll_obj=this;
var scroll_box=scroll_obj.find(".box");
var scroll_list=scroll_box.find(".list");
var scroll_array=scroll_list.find("li");
var scroll_num=scroll_array.length;
if(scroll_num<=1){return;};
/*
item_width 内部元素的宽度
item_height 内部元素的高度
*/
var item_width,item_height;
item_width=scroll_array.outerwidth();
item_height=scroll_array.outerheight();
var srcoll_html,scroll_run,plus_val,minus_val,scroll_val;
if(direction=="left"||direction=="right"){
if(item_width*scroll_num<=scroll_box.outerwidth()){return;};
plus_val="left";
minus_val="right";
scroll_val=item_width;
}else{
if(item_height*scroll_num<=scroll_box.outerheight()){return;};
plus_val="top";
minus_val="bottom";
scroll_val=item_height;
};
// 添加左右操作按钮
srcoll_html="";
if(scroll_obj.find(".plus").length<=0&&settings.plus){srcoll_html+="";};
if(scroll_obj.find(".minus").length<=0&&settings.minus){srcoll_html+="";};
scroll_obj.append(srcoll_html);
var scroll_plus=scroll_obj.find(".plus");
var scroll_minus=scroll_obj.find(".minus");
// 添加后补元素
scroll_list.append(scroll_list.html());
// 自动滚动函数
var scrollauto=function(){
if(settings.auto){
scroll_run=setinterval(function(){
scrollstart(direction);
},settings.time);
}else{
return;
};
};
// 开始滚动函数
var scrollstart=function(d){
controlremove();
scroll_list.stop(true);
/*
scroll_max 滚动的最大限度
scroll_px 滚动的距离
*/
var scroll_max,scroll_px;
switch(d){
case "left":
case "top":
if(parseint(scroll_list.css(plus_val))==0){
scroll_list.css(plus_val,-(scroll_num*scroll_val));
};
scroll_max=0;
scroll_px=parseint(scroll_list.css(plus_val))+(scroll_val*settings.step);
if(scroll_px>scroll_max){scroll_px=scroll_max};
if(d=="left"){
scroll_list.animate({left:scroll_px},settings.speed,function(){
if(parseint(scroll_list.css(plus_val))>=0){
scroll_list.css(plus_val,-(scroll_num*scroll_val));
};
controladd();
});
}else{
scroll_list.animate({top:scroll_px},settings.speed,function(){
if(parseint(scroll_list.css(plus_val))>=0){
scroll_list.css(plus_val,-(scroll_num*scroll_val));
};
controladd();
});
};
break;
case "right":
case "bottom":
scroll_max=-(scroll_num*scroll_val);
scroll_px=parseint(scroll_list.css(plus_val))-(scroll_val*settings.step);
if(scroll_px