/**
rocktabs 图片切换
caratename:chenxihu
caratetime:214-04-06 21:40:00
email:qqqq2900@126.com
homepage:www.xh829.com
*/
(function ($) {
function rocksilder(options){
var rand = ''+parseInt(Math.random()*99999)+'';
var me = this;
this.rand = rand;
for(var i1 in options)this[i1]=options[i1];
//初始化
this.init = function(){
var i,len=this.data.length;
this.oldoi = -1;
var s = '
';
if(len==0)return;
for(i=0;i
';
s+='';
s+=' ';
}
var bo = 0;
if(this.titlebool){
bo = 30;
s+=''+this.data[0].title+'
';
}
s+='';
s+='';
if(this.view==''){
$('body').append(s);
}else{
$('#'+this.view+'').html(s);
}
this.mobj = $('#rocksilder_'+this.rand+'');
this.mobj.find('div[index]').click(function(){
me._click(this);
return false;
});
this._showview(0);
};
this._click=function(o1){
var oi= parseFloat($(o1).attr('index'));
var d = this.data[oi];
if(this.onclick){
this.onclick(d);
}else{
if(d.url)js.location(d.url);
}
};
this._showview=function(oi){
clearTimeout(this.timeoutobj);
if(!get('rocksilder_'+this.rand+''))return;
var len = this.data.length;
if(oi>=len)oi=0;
var i,s='';
if(this.oldoi>=0){
this.mobj.find('div[index="'+this.oldoi+'"]').hide();
this.mobj.find('div[index="'+oi+'"]').show();
}else{
this.mobj.find('div[index]').hide();
this.mobj.find('div[index="'+oi+'"]').show();
}
$('#rocksildertitle_'+this.rand+'').html(this.data[oi].title);
for(i=0;i0)s+=' ';
if(i==oi){
s+='●';
}else{
s+='○';
}
}
$('#rocksildertitlev_'+this.rand+'').html(s).find('span[xu]').click(function(){
var xu = parseFloat($(this).attr('xu'));
me._showview(xu);
return false;
});
this.oldoi = oi;
this.timeoutobj = setTimeout(function(){me._showview(oi+1);},this.changtime);
};
this.remove=function(){
clearTimeout(this.timeoutobj);
$('#rocksilder_'+this.rand+'').remove();
}
}
$.rocksilder = function(options){
var defaultVal = {
'view': '',
'data':[],
'height' :'150px',
'titlebool':true,
'onclick':false,
'changtime':5000 //5秒
};
var can = $.extend({}, defaultVal, options);
var clsa = new rocksilder(can);
clsa.init();
return clsa;
};
})(jQuery);