WEB开发经常实用到一种情况,即某个容器内的各项轮流循环播放显示,同时有相应的导航条提示,因为这个在很多地方可以使用,而且功能很相似的,所以写一个这样的播放功能,共享一下,需要注意的是这个需要jQuery的支持, 这个自己网上搜索下载即可,下面总结出来如下,直接看代码,

一、把如下保存为一个独立的文件 itemPlayerApp.js :
//attend: this need jQuery.js support
var itemPlayerApp={
author:'shenzhenNBA',
version:'v1.0',
appMaxNum:0,
playData:'1xplay',
playerID:"",
speed:3000,
appPlay:function(){
var f=this.playData.toLowerCase().split('x');
if(f[1]=='play'){
var i;
try{i=parseInt(f[0]);}catch(e){i=0;}
if(i>=this.appMaxNum){i=0;}
this.appTab(i);
this.playData=(++i)+"xplay";
}
},
appTab:function(tabIndex){
var k,j;
try{k=parseInt(tabIndex);}catch(e){k=0;}
for(j=0;j<this.appMaxNum;j++){
if(k==j){
$('#itemNav'+j).css({'background-color':'#333333','color':'#FFFFFF'});
$('#item'+j).show('fast');
}else{
$('#itemNav'+j).css({'background-color':'#CCCCCC','color':'#000000'});
$('#item'+j).hide('fast');
}
}
},
appActive:function(){
var _this = this;
this.playerID = setInterval(function(){ _this.appPlay(); },this.speed);
},
init:function(refContainerId,intervalTime,refWidth,refHeight){
var cid = "";
var w = 300;
var h = 200;
if(refContainerId == 'undefined' || refContainerId == null || refContainerId == ''){
return;
}else{
cid = $.trim(refContainerId);
}
if(refWidth == 'undefined' || refWidth == null || refWidth == ''){
w = 300;
}else{
w = parseInt(refWidth);
}
if(refHeight == 'undefined' || refHeight == null || refHeight == ''){
h = 200;
}else{
h = parseInt(refHeight);
}
$('#' + cid).css({"position":"relative",'width':w,'height':h,'overflow':'hidden'});
$('#' + cid + "NavCon").css({'color':'#333333','height':'26px','position':'absolute','width':'95%','left':'0','bottom':'3px','text-align':'right','display':'block'});
var t = 0;
if(intervalTime == 'undefined' || intervalTime == null){
t = 3000;
}else{
try{ t = parseInt(intervalTime);}catch(e){ t = 3000;}
}
this.speed = t;
var navList = "#" + cid + "NavCon a";
this.appMaxNum = $(navList).size();
if(0 == this.appMaxNum){ return; }
var _this = this;
$(navList).each(function(i){
$(this).css({'padding':'2px 5px','margin-right':'2px','background-color':'#CCCCCC'});
if(i == 0){
$(this).css({'background-color':'#333333','color':'#FFFFFF'});
}
$(this).mouseover(function(){
_this.playData=i+'xstop';
_this.appTab(i);
});
$(this).mouseout(function(){
_this.playData=i+'xplay';
_this.appTab(i);
});
});
}
};
二、如何使用:
1.需要使用的web页面中引入jQery文件和本 itemPlayerApp.js 文件,例如:
<script language="javascript" src="xpath/itemPlayer.js"></script>
2.建立如下格式的HTML文件
<div id="containerID"> <div id="containerIDNavCon"> <a id="itemNav0" class="item1" href="#">1</a> <a id="itemNav1" class="item1" href="#">2</a> <a id="itemNav2" class="item1" href="#">3</a> </div> <div id="containerIDItemCon"> <a id="item0" href="#"><img src="img/pic0.jpg" width="300" height="200"></a> <a id="item1" href="#"><img src="img/pic1.jpg" width="300" height="200"></a> <a id="item2" href="#"><img src="img/pic2.jpg" width="300" height="200"></a> </div> </div>
注意:因为尽量简单,所以需要建立适当格式的HTML,主要要求如下,注意颜色部分,
//A, id = containerIDNavCon和 id = containerIDItemCon 中的连接 A 元素的数量应该相等;
//B, 导航容器的 ID 构成应为主容器 ID 加上 NavCon,如上 containerIDNavCon;
//C, 导航容器中的每个 A 元素的 ID 构成为,itemNav 加上以0开始的递增数字序列,如上面的绿色部分;
//D, 显示项目容器内的每个 A 元素的 ID 构成为,item 加上以0开始的递增数字序列,如上面的紫色部分;
3.在WEB页面中的加载事件onload,初始化和启用该轮播功能,例如:
window.onload=function(){
itemPlayerApp.init('containerID',3000,300,200);
itemPlayerApp.active();
}
三、如下一个例子
假如所有文件都放在一个文件夹里,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TEST</title>
<script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="itemPlayerApp.js"></script>
<style type="text/css">
*{font-family:"宋体",verdana,arial; font-size:12px;color:#000000;}
#playerBox{font-family:"宋体",verdana,arial; font-size:12px;color:#000000;}
</style>
</head>
<body>
<div id="playerBox" class="columnLeft01 box02">
<div id="playerBoxNavCon">
<a id="itemNav0" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >1</a>
<a id="itemNav1" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >2</a>
<a id="itemNav2" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >3</a>
</div>
<div id="playerBoxItemCon">
<a id="item0" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif" width="100%" height="200" border="0"></a>
<a id="item1" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="http://csdnimg.cn/www/images/csdnindex_logo.gif" width="100%" height="200" border="0"></a>
<a id="item2" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="http://avatar.csdn.net/5/1/9/1_shenzhennba.jpg" width="100%" height="200" border="0"></a>
</div>
</div>
<p> </p>
<p>项目循环轮播功能</p>
<script language="javascript" type="text/javascript">
window.onload=function(){
itemPlayerApp.init('playerBox',3000,300,200);
itemPlayerApp.appActive();
}
</script>
</body>
</html>
提示: jQuery.js 的文件请网上自己下载。
在使用到的时候直接使用即可。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
# jquery
# 轮播器
# jquery实现图片轮播器
# 教你一步步用jQyery实现轮播器
# 宋体
# 上以
# 的是
# 容器内
# 放在
# 网上
# 可以使用
# 如何使用
# 需要注意
# 大家多多
# 保存为
# 很相似
# 文件夹里
# 导航条
# 加载
# 有相应
# return
# null
# setInterval
# trim
相关文章:
建站主机是什么?如何选择适合的建站主机?
香港代理服务器配置指南:高匿IP选择、跨境加速与SEO优化技巧
如何通过cPanel快速搭建网站?
黑客入侵网站服务器的常见手法有哪些?
测试制作网站有哪些,测试性取向的权威测试或者网站?
如何快速搭建高效服务器建站系统?
建站上传速度慢?如何优化加速网站加载效率?
云南网站制作公司有哪些,云南最好的招聘网站是哪个?
如何选择高效响应式自助建站源码系统?
Java解压缩zip - 解压缩多个文件或文件夹实例
如何在Golang中使用encoding/gob序列化对象_存储和传输数据
免费视频制作网站,更新又快又好的免费电影网站?
建站主机服务器选购指南:轻量应用与VPS配置解析
如何选择适合PHP云建站的开源框架?
如何在阿里云部署织梦网站?
如何在云主机上快速搭建多站点网站?
深圳网站制作案例,网页的相关名词有哪些?
制作网站的模板软件,网站怎么建设?
北京网站制作公司哪家好一点,北京租房网站有哪些?
如何通过VPS建站无需域名直接访问?
如何在企业微信快速生成手机电脑官网?
如何快速搭建安全的FTP站点?
头像制作网站在线观看,除了站酷,还有哪些比较好的设计网站?
如何通过云梦建站系统实现SEO快速优化?
如何通过山东自助建站平台快速注册域名?
如何在阿里云虚拟机上搭建网站?步骤解析与避坑指南
大学网站设计制作软件有哪些,如何将网站制作成自己app?
Python多线程使用规范_线程安全解析【教程】
微课制作网站有哪些,微课网怎么进?
建站168自助建站系统:快速模板定制与SEO优化指南
建站之星2.7模板:企业网站建设与h5定制设计专题
无锡营销型网站制作公司,无锡网选车牌流程?
如何高效配置IIS服务器搭建网站?
小型网站建站如何选择虚拟主机?
黑客如何通过漏洞一步步攻陷网站服务器?
建站ABC备案流程中有哪些关键注意事项?
家庭建站与云服务器建站,如何选择更优?
公司门户网站制作公司有哪些,怎样使用wordpress制作一个企业网站?
香港服务器网站推广:SEO优化与外贸独立站搭建策略
如何在云服务器上快速搭建个人网站?
上海网站制作网站建设公司,建筑电工证网上查询系统入口?
网站制作专业公司有哪些,如何制作一个企业网站,建设网站的基本步骤有哪些?
建站之星导航菜单设置与功能模块配置全攻略
阿里云网站搭建费用解析:服务器价格与建站成本优化指南
如何在IIS服务器上快速部署高效网站?
如何在阿里云香港服务器快速搭建网站?
如何快速搭建高效WAP手机网站吸引移动用户?
深圳网站制作公司好吗,在深圳找工作哪个网站最好啊?
重庆市网站制作公司,重庆招聘网站哪个好?
如何通过主机屋免费建站教程十分钟搭建网站?
*请认真填写需求信息,我们会在24小时内与您取得联系。