JS實(shí)現(xiàn)的多張圖片輪流播放幻燈片效果
本文實(shí)例講述了JS實(shí)現(xiàn)的多張圖片輪流播放幻燈片效果。分享給大家供大家參考,具體如下:
<body style="width: 715px; height: 95px;"> <script language="javascript" type="text/javascript"> <!-- /************************************************** 名稱: 圖片輪播類 創(chuàng)建時(shí)間: 2010-07-11 zhangty 示例: 頁(yè)面中已經(jīng)存在名為imgPlayer(或者別的ID也行)的節(jié)點(diǎn). PImgPlayer.addItem( "test", "http://www.pomoho.com", "http://static.pomoho.com/static/samesong/images/logo5.jpg"); PImgPlayer.addItem( "test2", "http://www.pomoho.com.cn", "http://static.pomoho.com/static/samesong/images/logo4.jpg"); PImgPlayer.addItem( "test3", "http://www.pomoho.com.cn", "http://static.pomoho.com/static/samesong/images/logo3.jpg"); PImgPlayer.init( "imgPlayer", 200, 230 ); 備注: 適用于一個(gè)頁(yè)面只有一個(gè)圖片輪播的地方. ***************************************************/ var PImgPlayer = { _timer : null, _items : [], _container : null, _index : 0, _imgs : [], intervalTime : 5000, //輪播間隔時(shí)間 init : function( objID, w, h, time ){ this.intervalTime = time || this.intervalTime; this._container = document.getElementById( objID ); this._container.style.display = "block"; this._container.style.width = w + "px"; this._container.style.height = h + "px"; this._container.style.position = "relative"; this._container.style.overflow = "hidden"; //this._container.style.border = "1px solid #fff"; var linkStyle = "display: block; TEXT-DECORATION: none;"; if( document.all ){ linkStyle += "FILTER:"; linkStyle += "progid:DXImageTransform.Microsoft.Barn(duration=0.5, motion='out', orientation='vertical') "; linkStyle += "progid:DXImageTransform.Microsoft.Barn ( duration=0.5,motion='out',orientation='horizontal') "; linkStyle += "progid:DXImageTransform.Microsoft.Blinds ( duration=0.5,bands=10,Direction='down' )"; linkStyle += "progid:DXImageTransform.Microsoft.CheckerBoard()"; linkStyle += "progid:DXImageTransform.Microsoft.Fade(duration=0.5,overlap=0)"; linkStyle += "progid:DXImageTransform.Microsoft.GradientWipe ( duration=1,gradientSize=1.0,motion='reverse' )"; linkStyle += "progid:DXImageTransform.Microsoft.Inset ()"; linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=1,irisStyle=PLUS,motion=out )"; linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=1,irisStyle=PLUS,motion=in )"; linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=1,irisStyle=DIAMOND,motion=in )"; linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=1,irisStyle=SQUARE,motion=in )"; linkStyle += "progid:DXImageTransform.Microsoft.Iris ( duration=0.5,irisStyle=STAR,motion=in )"; linkStyle += "progid:DXImageTransform.Microsoft.RadialWipe ( duration=0.5,wipeStyle=CLOCK )"; linkStyle += "progid:DXImageTransform.Microsoft.RadialWipe ( duration=0.5,wipeStyle=WEDGE )"; linkStyle += "progid:DXImageTransform.Microsoft.RandomBars ( duration=0.5,orientation=horizontal )"; linkStyle += "progid:DXImageTransform.Microsoft.RandomBars ( duration=0.5,orientation=vertical )"; linkStyle += "progid:DXImageTransform.Microsoft.RandomDissolve ()"; linkStyle += "progid:DXImageTransform.Microsoft.Spiral ( duration=0.5,gridSizeX=16,gridSizeY=16 )"; linkStyle += "progid:DXImageTransform.Microsoft.Stretch ( duration=0.5,stretchStyle=PUSH )"; linkStyle += "progid:DXImageTransform.Microsoft.Strips ( duration=0.5,motion=rightdown )"; linkStyle += "progid:DXImageTransform.Microsoft.Wheel ( duration=0.5,spokes=8 )"; linkStyle += "progid:DXImageTransform.Microsoft.Zigzag ( duration=0.5,gridSizeX=4,gridSizeY=40 ); width: 100%; height: 100%"; } // 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;"; // var liStyle = "margin:0;list-style-type: none; margin:0;padding:0; float:right;"; // var baseSpacStyle = "clear:both; display:block; width:23px;line-height:18px; font-size:12px; FONT-FAMILY:'宋體';opacity: 0.6;"; baseSpacStyle += "border:1px solid #fff;border-right:0;border-bottom:0;"; baseSpacStyle += "color:#fff;text-align:center; cursor:pointer; "; // var ulHTML = ""; for(var i = this._items.length -1; i >= 0; i--){ var spanStyle = ""; if( i==this._index ){ spanStyle = baseSpacStyle + "background:#ff0000;"; //初始化底部數(shù)字的顏色 } else { spanStyle = baseSpacStyle + "background:#c0c0c0;"; //初始化底部數(shù)字的背景顏色 } ulHTML += "<li style=\""+liStyle+"\">"; 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>"; ulHTML += "</li>"; } // 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>"; this._container.innerHTML = html; var link = this._container.getElementsByTagName("A")[0]; link.style.width = w + "px"; link.style.height = h + "px"; link.style.background = 'url(' + this._items[0].img + ') no-repeat center center'; // this._timer = setInterval( "PImgPlayer.play()", this.intervalTime ); }, addItem : function( _title, _link, _imgURL ){ this._items.push ( {title:_title, link:_link, img:_imgURL } ); var img = new Image(); img.src = _imgURL; this._imgs.push( img ); }, play : function( index ){ if( index!=null ){ this._index = index; clearInterval( this._timer ); this._timer = setInterval( "PImgPlayer.play()", this.intervalTime ); } else { this._index = this._index<this._items.length-1 ? this._index+1 : 0; } var link = this._container.getElementsByTagName("A")[0]; if(link.filters){ var ren = Math.floor(Math.random()*(link.filters.length)); link.filters[ren].Apply(); link.filters[ren].play(); } link.href = this._items[this._index].link; link.title = this._items[this._index].title; link.style.background = 'url(' + this._items[this._index].img + ') no-repeat center center'; // var liStyle = "margin:0;list-style-type: none; margin:0;padding:0; float:right;"; var baseSpacStyle = "clear:both; display:block; width:23px;line-height:18px; font-size:12px; FONT-FAMILY:'宋體'; opacity: 0.6;"; baseSpacStyle += "border:1px solid #fff;border-right:0;border-bottom:0;"; baseSpacStyle += "color:#fff;text-align:center; cursor:pointer; "; var ulHTML = ""; for(var i = this._items.length -1; i >= 0; i--){ var spanStyle = ""; if( i==this._index ){ spanStyle = baseSpacStyle + "background:#ff0000;"; //數(shù)字的顏色 } else { spanStyle = baseSpacStyle + "background:#c0c0c0;"; //數(shù)字的背景顏色 } ulHTML += "<li style=\""+liStyle+"\">"; 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>"; ulHTML += "</li>"; } this._container.getElementsByTagName("UL")[0].innerHTML = ulHTML; }, mouseOver : function(obj){ var i = parseInt( obj.innerHTML ); if( this._index!=i-1){ obj.style.color = "#ff0000"; } }, mouseOut : function(obj){ obj.style.color = "#fff"; } } --> </script> <div id="imgADPlayer"></div> <script> PImgPlayer.addItem( "拉手網(wǎng)", "http://www.lashou.com/", "./images/1001.jpg"); PImgPlayer.addItem( "糯米網(wǎng)", "http://www.nuomi.com/", "./images/1002.jpg"); PImgPlayer.addItem( "美團(tuán)網(wǎng)", "http://www.meituan.com/", "./images/1003.jpg"); PImgPlayer.init( "imgADPlayer", 715, 95 ); </script> </body>
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript切換特效與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript動(dòng)畫特效與技巧匯總》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
- js手動(dòng)播放圖片實(shí)現(xiàn)圖片輪播效果
- javascript控制圖片播放的實(shí)現(xiàn)代碼
- JS特效實(shí)現(xiàn)圖片自動(dòng)播放并可控的效果
- javascript+html5實(shí)現(xiàn)仿flash滾動(dòng)播放圖片的方法
- javascript實(shí)現(xiàn)圖片循環(huán)漸顯播放的方法
- js實(shí)現(xiàn)幻燈片播放圖片示例代碼
- javascript 控制圖片播放代碼
- 比較炫的圖片播放器 js 焦點(diǎn)效果代碼
- js 新浪的一個(gè)圖片播放圖片輪換效果代碼
- JS實(shí)現(xiàn)圖片自動(dòng)播放效果
相關(guān)文章
JavaScript實(shí)現(xiàn)控制并發(fā)請(qǐng)求數(shù)量的方法詳解
這篇文章主要為大家詳細(xì)介紹了JavaScript如何實(shí)現(xiàn)控制并發(fā)請(qǐng)求數(shù)量,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-02-02JavaScript實(shí)現(xiàn)開關(guān)等效果
本文給大家分享一段簡(jiǎn)單的代碼基于js實(shí)現(xiàn)開關(guān)燈效果,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧2017-09-09javascript實(shí)現(xiàn)點(diǎn)亮燈泡特效示例
這篇文章主要介紹了javascript實(shí)現(xiàn)點(diǎn)亮燈泡特效示例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-10-10JavaScript DSL 流暢接口(使用鏈?zhǔn)秸{(diào)用)實(shí)例
這篇文章主要介紹了JavaScript DSL 流暢接口(使用鏈?zhǔn)秸{(diào)用)實(shí)例,本文講解了DSL 流暢接口、DSL 表達(dá)式生成器等內(nèi)容,需要的朋友可以參考下2015-03-03javascript分頁(yè)代碼實(shí)例分享(js分頁(yè))
這篇文章主要介紹了javascript分頁(yè)實(shí)例,大家參考使用吧2013-12-12微信小程序獲取手機(jī)號(hào)授權(quán)用戶登錄功能
微信小程序中有許多地方需要用戶注冊(cè)用戶信息的地方,用戶需要填寫手機(jī)號(hào)等,下面小編給大家分享微信小程序獲取手機(jī)號(hào)授權(quán)用戶登錄功能,需要的朋友參考下吧2017-11-11JavaScript數(shù)據(jù)結(jié)構(gòu)之廣義表的定義與表示方法詳解
這篇文章主要介紹了JavaScript數(shù)據(jù)結(jié)構(gòu)之廣義表的定義與表示方法,簡(jiǎn)單講述了廣義表的原理與相關(guān)概念,并結(jié)合實(shí)例形式分析了javascript定義與使用廣義表的相關(guān)操作技巧,需要的朋友可以參考下2017-04-04