js實現(xiàn)有過渡漸變效果的圖片輪播相冊(兼容IE,ff)
更新時間:2016年01月19日 09:04:02 作者:xiongchao2011
這篇文章主要介紹了js實現(xiàn)有過渡漸變效果的圖片輪播相冊,兼容IE、ff,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例介紹了js實現(xiàn)圖片輪播相冊,具有過渡漸變效果,分享給大家供大家參考,具體內(nèi)容如下
思路很簡單,用2個屬性保存當(dāng)前圖片和上一張圖片,用2個定時器分別控制透明度和當(dāng)前過渡的圖片。
<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; // 過渡一次的間隔時間(過渡時間+圖片顯示時間)
this.timer; // 定時器:控制當(dāng)前顯示的圖片
this.container = cnt;
this.curFrame = 0;
this.oldFrame = 0;
this.controls = control; // 按鈕集合
Global = this; // 獲取對象的指針
this.run = function(){
this.timer = window.setInterval("Global.showFrame()", this.interval);
}
// 按鈕的處理程序
this.go = function(i){
curOpac = 0; // 透明度歸0
this.curFrame = i; // 當(dāng)前要過渡的圖片
this.stop(); // 清空計時器
this.showFrame(); // 當(dāng)前圖片過渡
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);
}
}
//開始
function startIt(){
var imgArr = [];
// 創(chuàng)建4個圖片對象保存圖片路徑
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>
以上就是本文的全部內(nèi)容,希望對大家學(xué)習(xí)javascript程序設(shè)計有所幫助。
相關(guān)文章
Javascript限制網(wǎng)頁只能在微信內(nèi)置瀏覽器中訪問
最近正在開發(fā)一個微信公眾賬號,其中有一項功能是用戶發(fā)送文字消息給公眾號,然后公眾號返回圖文消息給用戶,用戶再點擊圖文消息即可跳轉(zhuǎn)到一個網(wǎng)頁鏈接,在微信的內(nèi)置瀏覽器中打開。2014-11-11
js數(shù)組高階函數(shù)之includes()方法總結(jié)
JS的數(shù)組是一種特殊的對象,其特點是在值的列表中按照順序存放值,在 JS中,數(shù)組是由中括號 [] 括起來的數(shù)值序列,本篇文章給大家介紹js數(shù)組高階函數(shù)——includes()方法,感興趣的朋友一起看看吧2023-12-12
Javascript獲取當(dāng)前時間函數(shù)和時間操作小結(jié)
這篇文章主要介紹了Javascript獲取當(dāng)前時間函數(shù)和時間操作小結(jié),本文根據(jù)項目實際需求總結(jié)而來,需要的朋友可以參考下2014-10-10
Javascript生成器(Generator)的介紹與使用
這篇文章主要給大家介紹了關(guān)于Javascript生成器(Generator)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
使用javaScript實現(xiàn)鼠標(biāo)拖拽事件
這篇文章主要為大家詳細介紹了使用javaScript實現(xiàn)鼠標(biāo)拖拽事件的相關(guān)資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-09-09

