js實(shí)現(xiàn)有過(guò)渡漸變效果的圖片輪播相冊(cè)(兼容IE,ff)
本文實(shí)例介紹了js實(shí)現(xiàn)圖片輪播相冊(cè),具有過(guò)渡漸變效果,分享給大家供大家參考,具體內(nèi)容如下
思路很簡(jiǎn)單,用2個(gè)屬性保存當(dāng)前圖片和上一張圖片,用2個(gè)定時(shí)器分別控制透明度和當(dāng)前過(guò)渡的圖片。
<HTML> <HEAD> <TITLE></TITLE> </HEAD> <style> #cnt{width:100%;height:80%;} .ctrl{text-align:center;border:1px solid gray;font-size:12px;cursor:pointer;} </style> <script defer='defer'> <!-- var curOpac = 0; var filterTimer; var isIE = /internet explorer/i.test(window.navigator.appName); function MyScroll(cnt, control){ this.data = []; // 存放圖片路徑 this.interval = 3000; // 過(guò)渡一次的間隔時(shí)間(過(guò)渡時(shí)間+圖片顯示時(shí)間) this.timer; // 定時(shí)器:控制當(dāng)前顯示的圖片 this.container = cnt; this.curFrame = 0; this.oldFrame = 0; this.controls = control; // 按鈕集合 Global = this; // 獲取對(duì)象的指針 this.run = function(){ this.timer = window.setInterval("Global.showFrame()", this.interval); } // 按鈕的處理程序 this.go = function(i){ curOpac = 0; // 透明度歸0 this.curFrame = i; // 當(dāng)前要過(guò)渡的圖片 this.stop(); // 清空計(jì)時(shí)器 this.showFrame(); // 當(dāng)前圖片過(guò)渡 this.run(); // 循環(huán)播放 } this.stop = function(){ window.clearInterval(this.timer); window.clearInterval(filterTimer); } this.showFrame = function(){ // 設(shè)置當(dāng)前按鈕樣式 this.controls[this.oldFrame].style.backgroundColor = "white"; this.controls[this.curFrame].style.backgroundColor = "gray"; if(isIE) this.container.style.filter = "alpha(opacity=0)"; else this.container.style.cssText = "-moz-opacity:0"; this.container.innerHTML = this.data[this.curFrame]; filterTimer = window.setInterval("blend()", 100); this.oldFrame = this.curFrame; this.curFrame ++; if(this.curFrame == this.data.length){ this.curFrame = 0; } } } // 增加透明度 function blend(){ curOpac+=10; if(isIE) Global.container.style.filter='alpha(opacity=' + curOpac + ')'; else Global.container.style.cssText = "-moz-opacity:" + curOpac/100.0; if(curOpac == 100){ curOpac = 0; window.clearInterval(filterTimer); } } //開(kāi)始 function startIt(){ var imgArr = []; // 創(chuàng)建4個(gè)圖片對(duì)象保存圖片路徑 for(var i=0;i<4;i++){ imgArr[i] = new Image(); imgArr[i].src = "images/banner" + (i + 1) + ".jpg"; } var controlArr = $("mainTb").getElementsByTagName("span"); for(var i=0;i<controlArr.length;i++){ controlArr[i].tag = i; controlArr[i].onclick = function(){ myScroll.go(this.tag); } } var myScroll = new MyScroll($("cnt"), controlArr); myScroll.data.push("<img src='" + imgArr[0].src + "'>"); myScroll.data.push("<img src='" + imgArr[1].src + "'>"); myScroll.data.push("<img src='" + imgArr[2].src + "'>"); myScroll.data.push("<img src='" + imgArr[3].src + "'>"); myScroll.go(0); } window.onload = startIt; function $(id){ return document.getElementById(id);} //--> </script> <BODY> <table width="300" height="100" id="mainTb"> <tr> <th rowspan="4"><div id="cnt"> </div></td> <td width="15"><span class="ctrl"> 1 </span></td> </tr> <tr> <td><span class="ctrl"> 2 </span></td> </tr> <tr> <td><span class="ctrl"> 3 </span></td> </tr> <tr> <td><span class="ctrl"> 4 </span></td> </tr> </table> </BODY> </HTML>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)javascript程序設(shè)計(jì)有所幫助。
- JS相冊(cè)圖片抖動(dòng)放大展示效果的示例代碼
- JavaScript制作3D旋轉(zhuǎn)相冊(cè)
- javascript實(shí)現(xiàn)QQ空間相冊(cè)展示源碼
- JavaScript+CSS相冊(cè)特效實(shí)例代碼
- JS實(shí)現(xiàn)的相冊(cè)圖片左右滾動(dòng)完整實(shí)例
- JavaScript實(shí)現(xiàn)相冊(cè)彈窗功能(zepto.js)
- 原生js實(shí)現(xiàn)移動(dòng)開(kāi)發(fā)輪播圖、相冊(cè)滑動(dòng)特效
- JavaScript實(shí)現(xiàn)一個(gè)前端會(huì)魔法的旋轉(zhuǎn)魔方相冊(cè)
相關(guān)文章
實(shí)例分析JS中的相等性判斷===、 ==和Object.is()
這篇文章主要給大家介紹了關(guān)于JS中相等性判斷===、 ==和Object.is()的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用JS具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11JavaScript實(shí)現(xiàn)計(jì)算多維嵌套數(shù)組深度
在前端開(kāi)發(fā)中,經(jīng)常會(huì)遇到需要處理多維嵌套的數(shù)據(jù)結(jié)構(gòu),并需要計(jì)算出它們的深度,本文就來(lái)講講如何使用JavaScript實(shí)現(xiàn)計(jì)算多維嵌套數(shù)組深度吧2023-06-06await/async無(wú)法捕獲與處理錯(cuò)誤信息的解決方案分享
async await 中添加錯(cuò)誤處理個(gè)人認(rèn)為是有必要的,下面這篇文章主要給大家介紹了關(guān)于await/async無(wú)法捕獲與處理錯(cuò)誤信息的解決方案,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02微信小程序中實(shí)現(xiàn)車(chē)牌輸入功能
我們都知道車(chē)牌是有一定規(guī)律的,本文實(shí)現(xiàn)了微信小程序中實(shí)現(xiàn)車(chē)牌輸入功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-05-05JavaSctit 利用FileReader和濾鏡上傳圖片預(yù)覽功能
FileReader 對(duì)象允許Web應(yīng)用程序異步讀取存儲(chǔ)在用戶計(jì)算機(jī)上的文件內(nèi)容,使用 File或 Blob對(duì)象指定要讀取的文件或數(shù)據(jù)。下面通過(guò)本文給大家分享JavaSctit 利用FileReader和濾鏡上傳圖片預(yù)覽功能,需要的朋友參考下吧2017-09-09基于JavaScript的簡(jiǎn)易計(jì)算器功能
這篇文章主要為大家詳細(xì)介紹了基于JavaScript的簡(jiǎn)易計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08TypeScript中的類(lèi)型斷言[as語(yǔ)法|<>語(yǔ)法]的使用
本文主要介紹了TypeScript中的類(lèi)型斷言[as語(yǔ)法|<>語(yǔ)法]的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06