javascript实现多张图片轮流展示效果代码
来源:互联网 发布:推荐一本自学java的书 编辑:程序博客网 时间:2024/04/28 21:37
看到很多网站上都有这样的效果,感觉很不错。想据为己有,但是扣起来实在是太麻烦,于是自己写了一个。下面是简单的代码实现(只实现了基本的功能,样式和一些细节还没修改来)
和以前一样,整合到了dojo中了,现在用的是1.0
基本的原理很简单,在一个固定的地方展示图片和标题。这里用的是数组。指定展示图片用的id,以及展示标题的容器id。
还有就是根据图片数组长度,动态创建一系列的手动切换按钮,点击按钮就展示相应的图片和标题。目前仅实现了简单的功能。比在ie7,firfox2, Safari下做了简单测试。大体上就这个样子吧。
下面是js
/**
* @fileoverview 定义了.
* @author hf
* @version 1.0
*/
if(!dojo._hasResource["com.hf.rollAd.RollerAd"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.hf.rollAd.RollerAd"] = true;
dojo.provide("com.hf.rollAd.RollerAd");
/**
* 图片轮流展示类
* @class 在一个窗口中轮番展示一些图片
* @constructor
* @titles {Array} 标题数组参数.
* @picUrls {Array}图片数组参数.
* @titleContainerId {String} 存放标题的容器id.
* @picContainerId {String} 存放图片的容器id.
* @manualControlContainerId {String} 存放转换控制的容器Id.
* @chandeSecond {int} 图片翻转的秒数.
* @return 返回一个com.hf.rollAd.RollerAd对象
*/
com.hf.rollAd.RollerAd = function (/*Array*/ titles, /*Array*/ picUrls,/*links*/ links,
/*String*/titleContainerId,/*String*/picId,
/*String*/manualControlContainerId,
/*int*/ chandeSecond){
/**
*一组标题
* @ type Array
*/
this.titles=titles;
/**
*一组图片链接
* @ type Array
*/
this.picUrls=picUrls;
this.links = links;
/**
*存放标题的容器id
* @ type String
*/
this.titleContainerId=titleContainerId;
/**
*存放图片的容器id
* @ type String
*/
this.picId=picId;
/**
*存放转换控制的容器Id
* @ type String
*/
this.manualControlContainerId=manualControlContainerId;
/**
*图片翻转的秒数
* @ type int
*/
this.chandeSecond=chandeSecond;
/*存放翻转图片的按钮的数组*/
this.buttonArray=[];
/*记录当前的图片序号,*/
this.currentCount= 0;
};
com.hf.rollAd.RollerAd.prototype.init=function (){
/*初始化手动图片切换的钮的生成*/
var manualControlContainer= document.getElementById(this.manualControlContainerId);
if(manualControlContainer!=null){
for(var i = 0;i<this.picUrls.length;i++){
var span = document.createElement("span");
span.innerHTML = ""+i;
span.index=i;
span.controller=this;
span.onmouseover=function(){
this.style.cursor="pointer";
};
span.onclick=function(){
this.controller.show(this.index);
};
this.addToManualPane(span);
/*存入数组中去*/
this.buttonArray[i] = span;
}//for
}//if
/*展示图片和标题层的数据*/
this.show(0);
};
/**
* 将手动按钮增加到对应的层上
* @return 返回void
*/
com.hf.rollAd.RollerAd.prototype.addToManualPane=function (span){
var manualControlContainer= document.getElementById(this.manualControlContainerId);
manualControlContainer.appendChild(span);
};
com.hf.rollAd.RollerAd.prototype.showNext=function (){
if(this.currentCount>=this.picUrls.length){
this.currentCount=0
}else{
this.currentCount++;
}
this.show(this.currentCount);
};
/**
* 在显示相应的图片和标题
* @return 返回void
*/
com.hf.rollAd.RollerAd.prototype.show=function (count){
if(count>=this.picUrls.length){
this.currentCount=0
}else{
this.currentCount=count;
}
this.showPic(this.currentCount);
this.showTitle(this.currentCount);
};
/**
* 在显示相应的图片
* @return 返回void
*/
com.hf.rollAd.RollerAd.prototype.showPic=function (count){
var pic = document.getElementById(this.picId);
pic.src=this.picUrls[count];
};
- javascript实现多张图片轮流展示效果代码
- javascript 实现多张图片轮流展示效果
- javaScript实现图片动态轮流展示
- Js实现多张图片无规律的轮流切换
- 多张图片轮流播放 幻灯片JS
- javascript图片展示效果
- js实现多张图片切换效果
- 实现多张图片浮动的效果
- JavaScript 图片切换展示效果
- JavaScript 图片滑动展示效果
- dede仿站时----实现简单图片滚动(轮流图)效果
- 实现图片轮流滑动
- 实现多张图片的浮动代码
- javascript实现图片滚动效果代码
- JavaScript 图片滑动展示效果javascript
- 用javascript 轮流显示图片
- UIScrollView利用分页展示多张图片
- 使用TransitionDrawable实现多张图片淡入淡出的效果
- javascript读取本地excel文档并显示在文本框中
- VB中如何声明及使用多维数组,多层数组及动态数组
- javacript实现关闭子窗口,刷新父窗口效果代码
- javascript实现WEB页面导出为EXCEL或WORD文档的方法
- javascript实现网易邮箱多附件上传功能代码
- javascript实现多张图片轮流展示效果代码
- *.android.com上不去的解决方法
- javascript实现一个IP只弹窗一次代码
- Java调用存储过程
- J2EE_Mysql数据源配置
- javascript如何快速拼装html字符串?
- 在榜“停留” holdover
- 用jquery解析JSON数据的方法
- People person 善交际的人