php轮播图代码_js实现图片轮播的代码实例(详细代码)

本篇文章给大家带来的内容是关于js实现图片轮播的代码实例(详细代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

broadcast.jsvar CarouselFigure = new Object();

//轮播图初始化定义函数

CarouselFigure.init = function(tmpobj){

//定义动画帧数(默认为:30)

this.frameNum = tmpobj.frameNum !=undefined ? tmpobj.frameNum : 30;

//定义一次轮播的时间(默认为:0.2s)

this.comsumeTime = tmpobj.comsumeTime !=undefined ? tmpobj.comsumeTime : 200;

//定义轮播图的宽高(默认宽高为:700px * 250px)

this.CFWidth = tmpobj.CFWidth !=undefined ? tmpobj.CFWidth : 700;

this.CFHeight = tmpobj.CFHeight !=undefined ? tmpobj.CFHeight : 250;

//定义轮播的风格

this.type = tmpobj.type == "small" ? 'small' : 'big';

//轮播图的按钮大小的宽高

this.AssowWidth = tmpobj.AssowWidth !=undefined ? tmpobj.AssowWidth : 76;

this.AssowHeight = tmpobj.AssowHeight !=undefined ? tmpobj.AssowHeight : 112;

//判断用户是否初始化

this.initFlag = true;

//是否允许轮播图运行

this.applicationflag = true;

}

CarouselFigure.start = function(){

/**

第一部分类容:初始化整个轮播图和其运行数据

*/

(function(){

//1. 判断用户是否进行初始化

if(CarouselFigure.initFlag == undefined){

CarouselFigure.init({});

}

//2.1 初始化整个轮播图的div的基本大小

$("#CarouselFigure").width(CarouselFigure.CFWidth).height(CarouselFigure.CFHeight).css("position","relative");

//2.2 最中央的大图实际大小为:

CarouselFigure.ImgWidth = CarouselFigure.CFWidth * 2/3;

CarouselFigure.ImgHeight = CarouselFigure.CFHeight - 6;

//3. 初始化轮播图按钮数据

CarouselFigure.setAssowdata = {

prev:{

top:(CarouselFigure.CFHeight - CarouselFigure.AssowHeight)/2 +"px",

left:CarouselFigure.CFWidth/6 - CarouselFigure.AssowWidth + 6 + "px",

originUrl:$("#CarouselFigure > img:eq(0)").attr("src"),

hoverUrl:$("#CarouselFigure > img:eq(1)").attr("src"),

},

next:{

top:(CarouselFigure.CFHeight - CarouselFigure.AssowHeight)/2 +"px",

left:CarouselFigure.CFWidth*5/6 + "px",

originUrl:$("#CarouselFigure > img:eq(2)").attr("src"),

hoverUrl:$("#CarouselFigure > img:eq(3)").attr("src"),

}

};

//4.1 初始化轮播图的url和src信息,存放到一个容器中

CarouselFigure.imageContains = [];

$("#CarouselFigure ul li img").each(function(){

var tmpobj = {src:$(this).attr("src"),href:$(this).attr("href")}

CarouselFigure.imageContains.push(tmpobj);

});

//4.2 对轮播图容器数据进行处理,当轮播图的个数3<= x <= 5 只能使用small风格类型。当轮播图的个数 x < 3 时, 停止运行

if(CarouselFigure.imageContains.length < 3){

CarouselFigure.applicationflag = false;

}else if(CarouselFigure.imageContains.length < 6){

CarouselFigure.type = 'small';

}

//4.3 对轮播容器数据按顺序进行增倍,保证有足够数据进行轮播

var objstr = JSON.stringify(CarouselFigure.imageC

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值