js轮播

本文介绍了一个轮播图插件的实现细节,包括初始化设置、图片切换效果及导航按钮交互等内容,适用于IE浏览器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1 var PImgPlayer = {
2 _timer : null,
3 _items : [],
4 _container : null,
5 _index : 0,
6 _imgs : [],
7 intervalTime : 5000, //轮播间隔时间
8 init : function( objID, w, h, time ){
9 this.intervalTime = time || this.intervalTime;
10 this._container = document.getElementById( objID );
11 this._container.style.display = "block";
12 this._container.style.width = w + "px";
13 this._container.style.height = h + "px";
14 this._container.style.position = "relative";
15 this._container.style.overflow = "hidden";
16 //this._container.style.border = "1px solid #fff";
17 var linkStyle = "display: block; TEXT-DECORATION: none;";
18 if( document.all ){
19 linkStyle += "FILTER:";
20 linkStyle += "progid:DXImageTransform.Microsoft.Barn(duration=0.5, motion='out', orientation='vertical') ";
21 linkStyle += "progid:DXImageTransform.Microsoft.Barn ( duration=0.5,motion='out',orientation='horizontal') ";
22 linkStyle += "progid:DXImageTransform.Microsoft.Blinds ( duration=0.5,bands=10,Direction='down' )";
23 linkStyle += "progid:DXImageTransform.Microsoft.CheckerBoard()";
24 linkStyle += "progid:DXImageTransform.Microsoft.Fade(duration=0.5,overlap=0)";
25 linkStyle += "progid:DXImageTransform.Microsoft.GradientWipe ( duration=1,gradientSize=1.0,motion='reverse' )";
26 linkStyle += "progid:DXImageTransform.Microsoft.Inset ()";
27 linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=1,irisStyle=PLUS,motion=out )";
28 linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=1,irisStyle=PLUS,motion=in )";
29 linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=1,irisStyle=DIAMOND,motion=in )";
30 linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=1,irisStyle=SQUARE,motion=in )";
31 linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=0.5,irisStyle=STAR,motion=in )";
32 linkStyle += "progid:DXImageTransform.Microsoft.RadialWipe ( duration=0.5,wipeStyle=CLOCK )";
33 linkStyle += "progid:DXImageTransform.Microsoft.RadialWipe ( duration=0.5,wipeStyle=WEDGE )";
34 linkStyle += "progid:DXImageTransform.Microsoft.RandomBars ( duration=0.5,orientation=horizontal )";
35 linkStyle += "progid:DXImageTransform.Microsoft.RandomBars ( duration=0.5,orientation=vertical )";
36 linkStyle += "progid:DXImageTransform.Microsoft.RandomDissolve ()";
37 linkStyle += "progid:DXImageTransform.Microsoft.Spiral ( duration=0.5,gridSizeX=16,gridSizeY=16 )";
38 linkStyle += "progid:DXImageTransform.Microsoft.Stretch ( duration=0.5,stretchStyle=PUSH )";
39 linkStyle += "progid:DXImageTransform.Microsoft.Strips ( duration=0.5,motion=rightdown )";
40 linkStyle += "progid:DXImageTransform.Microsoft.Wheel ( duration=0.5,spokes=8 )";
41 linkStyle += "progid:DXImageTransform.Microsoft.Zigzag ( duration=0.5,gridSizeX=4,gridSizeY=40 ); width: 100%; height: 100%";
42 }
43 //
44 var ulStyle = "margin:0;width:"+w+"px;position:absolute;z-index:999;right:5px;FILTER:Alpha(Opacity=30,FinishOpacity=90, Style=1);overflow: hidden;bottom:-1px;height:16px; border-right:1px solid #fff;";
45 //
46 var liStyle = "margin:0;list-style-type: none; margin:0;padding:0; float:right;";
47 //
48 var baseSpacStyle = "clear:both; display:block; width:23px;line-height:18px; font-size:12px; FONT-FAMILY:'宋体';opacity: 0.6;";
49 baseSpacStyle += "border:1px solid #fff;border-right:0;border-bottom:0;";
50 baseSpacStyle += "color:#fff;text-align:center; cursor:pointer; ";
51 //
52 var ulHTML = "";
53 for(var i = this._items.length -1; i >= 0; i--){
54 var spanStyle = "";
55 if( i==this._index ){
56 spanStyle = baseSpacStyle + "background:#ff0000;";
57 } else {
58 spanStyle = baseSpacStyle + "background:#000;";
59 }
60 ulHTML += "<li style=\""+liStyle+"\">";
61 ulHTML += "<span onmouseover=\"PImgPlayer.mouseOver(this);\" onmouseout=\"PImgPlayer.mouseOut(this);\" style=\""+spanStyle+"\" onclick=\"PImgPlayer.play("+i+");return false;\" herf=\"javascript:;\" title=\"" + this._items[i].title + "\">" + (i+1) + "</span>";
62 ulHTML += "</li>";
63 }
64 //
65 var html = "<a href=\""+this._items[this._index].link+"\" title=\""+this._items[this._index].title+"\" target=\"_blank\" style=\""+linkStyle+"\"></a><ul style=\""+ulStyle+"\">"+ulHTML+"</ul>";
66 this._container.innerHTML = html;
67 var link = this._container.getElementsByTagName("A")[0];
68 link.style.width = w + "px";
69 link.style.height = h + "px";
70 link.style.background = 'url(' + this._items[0].img + ') no-repeat center center';
71 //
72 this._timer = setInterval( "PImgPlayer.play()", this.intervalTime );
73 },
74 addItem : function( _title, _link, _imgURL ){
75 this._items.push ( {title:_title, link:_link, img:_imgURL } );
76 var img = new Image();
77 img.src = _imgURL;
78 this._imgs.push( img );
79 },
80 play : function( index ){
81 if( index!=null ){
82 this._index = index;
83 clearInterval( this._timer );
84 this._timer = setInterval( "PImgPlayer.play()", this.intervalTime );
85 } else {
86 this._index = this._index<this._items.length-1 ? this._index+1 : 0;
87 }
88 var link = this._container.getElementsByTagName("A")[0];
89 if(link.filters){
90 var ren = Math.floor(Math.random()*(link.filters.length));
91 link.filters[ren].Apply();
92 link.filters[ren].play();
93 }
94 link.href = this._items[this._index].link;
95 link.title = this._items[this._index].title;
96 link.style.background = 'url(' + this._items[this._index].img + ') no-repeat center center';
97 //
98 var liStyle = "margin:0;list-style-type: none; margin:0;padding:0; float:right;";
99 var baseSpacStyle = "clear:both; display:block; width:23px;line-height:18px; font-size:12px; FONT-FAMILY:'宋体'; opacity: 0.6;";
100 baseSpacStyle += "border:1px solid #fff;border-right:0;border-bottom:0;";
101 baseSpacStyle += "color:#fff;text-align:center; cursor:pointer; ";
102 var ulHTML = "";
103 for(var i = this._items.length -1; i >= 0; i--){
104 var spanStyle = "";
105 if( i==this._index ){
106 spanStyle = baseSpacStyle + "background:#ff0000;";
107 } else {
108 spanStyle = baseSpacStyle + "background:#000;";
109 }
110 ulHTML += "<li style=\""+liStyle+"\">";
111 ulHTML += "<span onmouseover=\"PImgPlayer.mouseOver(this);\" onmouseout=\"PImgPlayer.mouseOut(this);\" style=\""+spanStyle+"\" onclick=\"PImgPlayer.play("+i+");return false;\" herf=\"javascript:;\" title=\"" + this._items[i].title + "\">" + (i+1) + "</span>";
112 ulHTML += "</li>";
113 }
114 this._container.getElementsByTagName("UL")[0].innerHTML = ulHTML;
115 },
116 mouseOver : function(obj){
117 var i = parseInt( obj.innerHTML );
118 if( this._index!=i-1){
119 obj.style.color = "#ff0000";
120 }
121 },
122 mouseOut : function(obj){
123 obj.style.color = "#fff";
124 }
125 }

 

转载于:https://www.cnblogs.com/huangxiang/archive/2012/01/17/2324805.html

jquery 图片播放器插件 作者:笑的自然 我的博客:http://blog.youkuaiyun.com/xxd851116 我的邮箱: xingxiudong@gmail.com 下载: 项目地址:http://code.google.com/p/imgplayer/ 历史下载: http://code.google.com/p/imgplayer/downloads/list jquery.fn.imgplayer.js最新下载地址:http://imgplayer.googlecode.com/svn/trunk/imgplayer/src/jquery.fn.imgplayer.js jquery.fn.imgplayer.min.js最新下载地址:http://imgplayer.googlecode.com/svn/trunk/imgplayer/src/jquery.fn.imgplayer.min.js 说明: 1. 项目编码为GBK 2. 目前播放模式支持 1:溶解,2:挂历模式,3:滑动(从左到右),4:滑动(从上到下),5:滑动(从下到上),6:滑动(从右到左),善不支持随机模式 3. 在IE6,IE8,FF下测试通过 4. 支持任意数量图片,使用简单 5. 考虑到图片占用空间较多,示例中图片来自网络,离线状态下需要自定义图片 由于采用纯JavaScript实现,动画效果比较简单,目前善不支持随机播放模式,希望广大编程爱好者提出建议和不足。 参数: imgCSS : 用户自定义图片样式 transition : 播放模式选项 1:溶解,2:挂历模式,3:滑动(从左到右),4:滑动(从上到下),5:滑动(从下到上),6:滑动(从右到左),23:随机 width : 播放器div容器的宽度 height : 播放器div容器的高度 time : 图片播放间隙时间,单位:毫秒 duration : 图片播放时间,单位:毫秒 onStart : 开始播放时执行的函数 onStop : 停止播放时执行的函数 onShow : 每页图片显示时执行的函数 onHide : 每页图片隐藏时执行的函数 使用示例: 1. 容器代码 <div id="imgContainer" style="margin-left:auto;margin-right:auto;margin-top:5px;display:none;"> <a href="" target="_blank" title=""><img src="" title="" /></a> ...... </div> 2. 导入jquery包(http://code.jquery.com/jquery-1.4.2.min.js) <script type="text/javascript" src="jquery-1.4.2.min.js"></script> 3. 导入imgplayer插件(http://imgplayer.googlecode.com/svn/trunk/imgplayer/src/jquery.fn.imgplayer.min.js) <script type="text/javascript" src="jquery.fn.imgplayer.min.js"></script> 4. 绑定播放函数(参数说明详见上述) var player = $("#imgContainer").playImgs({ imgCSS : {'width' : '800px', 'height' : '600px'}, width : '800px', height: '600px', time : '5000', transition : 1, duration : 2000 }).start(); 更新日志: v1.2(2010-02-24): 1.修改了标题栏右侧冲出容器的bug 2.添加了duration参数,可自定义图片动画效果时间 v1.1(2009-09-23): 1.修改了鼠标停留播放器和序号标签上图片继续播放的问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值