File: /web/data/www.tbbprovision.com/static/js/scrollExt.3.1.js
(function($j,w){
w.scrollExt = function (p){
var _this=this;
var defaultParam={
Type : 1,//1、为无缝循环滚动,2、边界,3为边界循环,
show : 1,//产品详细页面小图标情况时,需要设置一个可见的子元素的个数。
auto : true,//是否自动执行
change : true,//是否支持左右方向切换滚动
hover : true,//是否支持鼠标经过停止
box : '',//移动的元素
item_ : '',//移动元素里面每一个子元素
itemWidth : '',//每一个子元素的宽度 左右移动需要设置
itemHeight : '',//每一个子元素的高度 上下移动需要设置
left : '',//向左或者向上切换按钮
right : '',//向右或者向下切换按钮
minlength : 2,//执行需要最小子元素个数
direction : 'l_r',//滚动方向 l_r-左右 t_b-上下
defaultTo : 'l',//默认滚动的方向
animateType : 'scroll',//滚动的类型。scroll-无疑滚动,step-步长移动
animateTime : 'slow',//slow-慢 normal-正常 fast-快
step : 1,//如果animateType设置为step ,这里要设置一个移动距离
time : 1000,//频率【自动滚动的时候需要配置】
opacity : 0.5//盒子移动时透明处理,不需要则传递1即可
};
var param=$j.extend({},defaultParam,p);
var init = function(){
_this.box=$j(param.box);
_this.item_=$j(param.item_);
_this.itemLength=_this.item_.length;
_this.itemWidth=parseInt(param.itemWidth);
_this.itemHeight=parseInt(param.itemHeight);
_this.boxWidth=_this.itemLength*_this.itemWidth;
_this.boxHeight=_this.itemLength*_this.itemHeight;
_this.left=$j(param.left);
_this.right=$j(param.right);
_this.step=parseInt(param.step);
_this.animateTime=param.animateTime;
_this.time=param.time;
_this.minlength=parseInt(param.minlength);
_this.defaultTo=param.defaultTo;
_this.myevent=0;
if(param.Type==1){
if(param.direction=='l_r'){
_this.box.width(_this.boxWidth*2).append(_this.item_.clone());
}else if(param.direction=='t_b'){
_this.box.height(_this.boxHeight*2).append(_this.item_.clone());
}
}else{
if(param.direction=='l_r'){
_this.box.width(_this.boxWidth);
}else if(param.direction=='t_b'){
_this.box.height(_this.boxHeight);
}
}
if(param.auto===true && _this.itemLength>=_this.minlength){
_this.autoscroll();
}
if(param.change===true && _this.itemLength>=_this.minlength){
if(param.Type==1){
_this.left.click(function(){
if(param.auto===true){
clearInterval(_this.myevent);
_this.defaultTo='l';
_this.myevent=setInterval(_this.scrollLeft,_this.time);
}else{
_this.scrollLeft();
}
});
_this.right.click(function(){
if(param.auto===true){
clearInterval(_this.myevent);
_this.defaultTo='r';
_this.myevent=setInterval(_this.scrollRight,_this.time);
}else{
_this.scrollRight();
}
});
}else if(param.Type==2||param.Type==3){
_this.left.click(function(){
_this.scrollLeft();
});
_this.right.click(function(){
_this.scrollRight();
});
}
}
if(param.auto===true && param.hover===true){
if(param.Type==1 && param.animateType=='scroll' && _this.itemLength>=_this.minlength ){
$j(_this.box).hover(
function(){
window.clearInterval(_this.myevent);
},
function(){
_this.autoscroll();
}
);
}
}
}
this.autoscroll=function(){
if(param.Type==1){
if(_this.defaultTo=='l'){
_this.myevent=setInterval(_this.scrollLeft,_this.time);
}else{
_this.myevent=setInterval(_this.scrollRight,_this.time);
}
}
}
this.scrollLeft=function(){
if(param.Type==1){
if(param.animateType=='scroll'){
if(param.direction=='l_r'){
var offset=parseInt(_this.box.css('marginLeft'));
if(offset>=0){
_this.box.css('marginLeft',"-"+_this.boxWidth+'px');
}
_this.box.css('marginLeft',"+=1px");
}else if(param.direction=='t_b'){
var offset=parseInt(_this.box.css('marginTop'));
if(offset>=0){
_this.box.css('marginTop',"-"+_this.boxHeight+"px");
}
_this.box.css('marginTop',"+=1px");
}
}else if(param.animateType='step'){
if(!_this.box.is(':animated')){
if(param.direction=='l_r'){
var offset=parseInt(_this.box.css('marginLeft'));
if(offset>=0){
_this.box.css('marginLeft',"-"+_this.boxWidth+'px');
}
_this.box.animate({'marginLeft':"+="+_this.step+"px"},_this.animateTime);
}else if(param.direction=='t_b'){
var offset=parseInt(_this.box.css('marginTop'));
if(offset>=0){
_this.box.css('marginTop',"-"+_this.boxHeight+"px");
}
_this.box.animate({'marginTop':"+="+_this.step+"px"},_this.animateTime);
}
}
}
}else if(param.Type==2){//type=2移动到边界就停止 ,没有自动效果,
if(param.direction=='l_r'){
var offset=parseInt(_this.box.css('marginLeft'));
if(!_this.box.is(":animated")){
if(offset<0){
_this.opacity();
_this.box.animate({'marginLeft':'+='+_this.step+"px"},_this.animateTime,function(){_this.removeOpacity();});
}
}
}else if(param.direction=='t_b'){
var offset=parseInt(_this.box.css('marginTop'));
if(!_this.box.is(":animated")){
if(offset<0){
_this.opacity();
_this.box.animate({'marginTop':'+='+_this.step+"px"},_this.animateTime,function(){_this.removeOpacity();});
}
}
}
}else if(param.Type==3){//type=3 移动到边界的时候,返回另一端
_this.opacity();
if(param.direction=='l_r'){
var offset=parseInt(_this.box.css('marginLeft'));
if(!_this.box.is(":animated")){
if(offset<0){
_this.box.animate({'marginLeft':'+='+_this.step+"px"},_this.animateTime,function(){_this.removeOpacity();});
}else{
_this.box.animate({'marginLeft':'-'+(_this.boxWidth-parseInt(param.show)*_this.itemWidth)+"px"},_this.animateTime,function(){_this.removeOpacity();});
}
}
}else if(param.direction=='t_b'){
var offset=parseInt(_this.box.css('marginTop'));
if(!_this.box.is(":animated")){
if(offset<0){
_this.box.animate({'marginTop':'+='+_this.step+"px"},_this.animateTime,function(){_this.removeOpacity();});
}else{
_this.box.animate({'marginTop':'-'+(_this.boxHeight-parseInt(param.show)*_this.itemHeight)+"px"},function(){_this.removeOpacity();});
}
}
}
}
}
this.scrollRight=function(){
if(param.Type==1){
if(param.animateType=='scroll'){
if(param.direction=='l_r'){
var offset=parseInt(_this.box.css('marginLeft'));
if(offset<=(-_this.boxWidth)){
_this.box.css('marginLeft','0px');
}
_this.box.css('marginLeft',"-=1px");
}else if(param.direction=='t_b'){
var offset=parseInt(_this.box.css('marginTop'));
if(offset<=-(_this.boxHeight)){
_this.box.css('marginTop',"0px");
}
_this.box.css('marginTop',"-=1px");
}
}else if(param.animateType='step'){
if(!_this.box.is(':animated')){
if(param.direction=='l_r'){
var offset=parseInt(_this.box.css('marginLeft'));
if(offset<=-(_this.boxWidth)){
_this.box.css('marginLeft','0px');
}
_this.box.animate({'marginLeft':"-="+_this.step+"px"},_this.animateTime,function(){_this.removeOpacity();});
}else if(param.direction=='t_b'){
var offset=parseInt(_this.box.css('marginTop'));
if(offset<=-(_this.boxHeight)){
_this.box.css('marginTop',"0px");
}
_this.box.animate({'marginTop':"-="+_this.step+"px"},_this.animateTime,function(){_this.removeOpacity();});
}
}
}
}else if(param.Type==2){//type=2移动到边界就停止 ,没有自动效果,
if(param.direction=='l_r'){
var offset=parseInt(_this.box.css('marginLeft'));
if(!_this.box.is(":animated")){
if(offset>-(_this.boxWidth-param.show*_this.itemWidth)){
_this.opacity();
_this.box.animate({'marginLeft':'-='+_this.step+"px"},_this.animateTime,function(){_this.removeOpacity();});
}
}
}else if(param.direction=='t_b'){
var offset=parseInt(_this.box.css('marginTop'));
if(!_this.box.is(":animated")){
if(offset>-(_this.boxHeight-param.show*_this.itemHeight)){
_this.opacity();
_this.box.animate({'marginTop':'-='+_this.step+"px"},_this.animateTime,function(){_this.removeOpacity();});
}
}
}
}else if(param.Type==3){//type=3 移动到边界的时候,返回另一端
_this.opacity();
if(param.direction=='l_r'){
var offset=parseInt(_this.box.css('marginLeft'));
if(!_this.box.is(":animated")){
if(offset>-(_this.boxWidth-parseInt(param.show)*_this.itemWidth)){
_this.box.animate({'marginLeft':'-='+_this.step+"px"},_this.animateTime,function(){_this.removeOpacity();});
}else{
_this.box.animate({'marginLeft':'0px'},_this.animateTime,function(){_this.removeOpacity();});
}
}
}else if(param.direction=='t_b'){
var offset=parseInt(_this.box.css('marginTop'));
if(!_this.box.is(":animated")){
if(offset>-(_this.boxHeight-parseInt(param.show)*_this.itemHeight)){
_this.box.animate({'marginTop':'-='+_this.step+"px"},_this.animateTime,function(){_this.removeOpacity();});
}else{
_this.box.animate({'marginTop':"0px"},_this.animateTime,function(){_this.removeOpacity();});
}
}
}
}
}
this.opacity=function(){
_this.box.css('opacity',param.opacity);
}
this.removeOpacity=function(){
_this.box.css('opacity',"1");
}
init();
}
})(jQuery,window)