自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

JavaScript圖片變換效果(IE only)

開發(fā) 前端
變換之前先設(shè)置兩個(gè)參數(shù)Transition和Duration,分別是變換效果和持續(xù)時(shí)間,其中Duration是浮點(diǎn)數(shù)。此外還有兩個(gè)屬性Enabled和Percent分別是是否激活濾鏡和當(dāng)前靜態(tài)濾鏡輸出在轉(zhuǎn)換進(jìn)程中所處的點(diǎn)。

仿照常見的那個(gè)圖片變換flash做的效果,純js。不過濾鏡變換只對(duì)應(yīng)ie,ff只能看到一般的切換。這個(gè)js做的效果最早在sina看到,這里把這個(gè)效果封裝好方便使用。

效果:

[[77981]]

程序說明:

圖片未開始轉(zhuǎn)換時(shí),由于沒有圖片會(huì)顯示一個(gè)紅x,所以隱藏圖片:

  1. this._img.style.visibility = "hidden"

ps:以前我用this._img.src = "javascript:void(0);";但這個(gè)在ie8會(huì)出錯(cuò)。

這個(gè)變換效果需要濾鏡,所以只支持ie。要使用變換濾鏡,要先設(shè)置filter:

  1. this._img.style.filter = "revealTrans()" 

變換之前先設(shè)置兩個(gè)參數(shù)Transition和Duration,分別是變換效果和持續(xù)時(shí)間,其中Duration是浮點(diǎn)數(shù)。

此外還有兩個(gè)屬性Enabled和Percent分別是是否激活濾鏡和當(dāng)前靜態(tài)濾鏡輸出在轉(zhuǎn)換進(jìn)程中所處的點(diǎn)。

設(shè)置完后還需要運(yùn)行apply和play方法,分別是應(yīng)用變換效果和運(yùn)行效果:

  1. with(this._img.filters.revealTrans){  
  2.     Transition = this.Transition; Duration = this.Duration; apply(); play();  
  3. }  

除了這兩個(gè)方法還有一個(gè)stop方法用來停止效果。

下面列出所有效果和對(duì)應(yīng)Transition值(參考手冊):

值 : 效果

0  : 矩形收縮轉(zhuǎn)換。

1  : 矩形擴(kuò)張轉(zhuǎn)換。

2  : 圓形收縮轉(zhuǎn)換。

3  : 圓形擴(kuò)張轉(zhuǎn)換。

4  : 向上擦除。

5  : 向下擦除。

6  : 向右擦除。

7  : 向左擦除。

8  : 縱向百葉窗轉(zhuǎn)換。

9  : 橫向百葉窗轉(zhuǎn)換。 

10 : 國際象棋棋盤橫向轉(zhuǎn)換。

11 : 國際象棋棋盤縱向轉(zhuǎn)換。

12 : 隨機(jī)雜點(diǎn)干擾轉(zhuǎn)換。

13 : 左右關(guān)門效果轉(zhuǎn)換。

14 : 左右開門效果轉(zhuǎn)換。

15 : 上下關(guān)門效果轉(zhuǎn)換。

16 : 上下開門效果轉(zhuǎn)換。

17 : 從右上角到左下角的鋸齒邊覆蓋效果轉(zhuǎn)換。

18 : 從右下角到左上角的鋸齒邊覆蓋效果轉(zhuǎn)換。

19 : 從左上角到右下角的鋸齒邊覆蓋效果轉(zhuǎn)換。

20 : 從左下角到右上角的鋸齒邊覆蓋效果轉(zhuǎn)換。

21 : 隨機(jī)橫線條轉(zhuǎn)換。

22 : 隨機(jī)豎線條轉(zhuǎn)換。

23 : 隨機(jī)使用上面可能的值轉(zhuǎn)換。

其中23比較特別,是隨機(jī)效果,程序默認(rèn)就是隨機(jī)效果。

設(shè)置完濾鏡效果后就修改圖片的src就開始轉(zhuǎn)換了。

然后設(shè)置鏈接:

  1. !!list["url"] ? (this._a.href = list["url"]) : this._a.removeAttribute("href");  

要注意的是這里用removeAttribute去掉a的href才能去掉鏈接,如果只設(shè)為空那么鏈接還是去不掉的。

#p#

使用說明:

首先要實(shí)例化一個(gè)對(duì)象:

  1. var rvt = new RevealTrans("idPicShow");  

idPicShow就是顯示變換的容器對(duì)象。

有以下這些可選參數(shù)和屬性:

屬性:默認(rèn)值//說明

Auto:  true,//是否自動(dòng)切換;Pause:  1000,//停頓時(shí)間(微妙);Duration: 1,//變換持續(xù)時(shí)間(秒);Transition: 23,//變換效果(23為隨機(jī))

List:  [],//數(shù)據(jù)集合,如果這里不設(shè)置可以用Add方法添加

onShow:  function(){}//變換時(shí)執(zhí)行

其中List是數(shù)據(jù)集合,其中每個(gè)元素結(jié)構(gòu)是這樣的:

  1. { img: 圖片url, text: 相關(guān)文本, url: 相關(guān)鏈接 } 

在使用時(shí)要注意,也可以在實(shí)例化之后用Add方法添加:

  1. rvt.Add('http://images.51cto.com/files/uploadimg/20120601/1019570.jpg', '圖片變換效果', 'http://www.cnblogs.com/cloudgamer/archive/2008/05/23/1205642.html');  
  2.  

可以一個(gè)一個(gè)添加,這樣方便后臺(tái)用循環(huán)輸出數(shù)據(jù)。

至于圖片列表、按鈕和文本顯示區(qū)域是自己擴(kuò)展的部分,詳細(xì)請看實(shí)例。

全部設(shè)置完成后就可以用Start開始變換程序了:

  1. rvt.Start(); 

程序代碼:

  1. var RevealTrans = Class.create();  
  2. RevealTrans.prototype = {  
  3.   initialize: function(container, options) {  
  4.     this._img = document.createElement("img");  
  5.     this._a = document.createElement("a");  
  6.       
  7.     this._timer = null;//計(jì)時(shí)器  
  8.     this.Index = 0;//顯示索引  
  9.     this._onIndex = -1;//當(dāng)前索引  
  10.       
  11.     this.SetOptions(options);  
  12.       
  13.     this.Auto = !!this.options.Auto;  
  14.     this.Pause = Math.abs(this.options.Pause);  
  15.     this.Duration = Math.abs(this.options.Duration);  
  16.     this.Transition = parseInt(this.options.Transition);  
  17.     this.List = this.options.List;  
  18.     this.onShow = this.options.onShow;  
  19.       
  20.     //初始化顯示區(qū)域  
  21.     this._img.style.visibility = "hidden";//第一次變換時(shí)不顯示紅x圖  
  22.     this._img.style.width = this._img.style.height = "100%"this._img.style.border = 0;  
  23.     this._img.onmouseover = Bind(thisthis.Stop);  
  24.     this._img.onmouseout = Bind(thisthis.Start);  
  25.     isIE && (this._img.style.filter = "revealTrans()");  
  26.       
  27.     this._a.target = "_blank";  
  28.       
  29.     $(container).appendChild(this._a).appendChild(this._img);  
  30.   },  
  31.   //設(shè)置默認(rèn)屬性  
  32.   SetOptions: function(options) {  
  33.     this.options = {//默認(rèn)值  
  34.         Auto:        true,//是否自動(dòng)切換  
  35.         Pause:        1000,//停頓時(shí)間(微妙)  
  36.         Duration:    1,//變換持續(xù)時(shí)間(秒)  
  37.         Transition:    23,//變換效果(23為隨機(jī))  
  38.         List:        [],//數(shù)據(jù)集合,如果這里不設(shè)置可以用Add方法添加  
  39.         onShow:        function(){}//變換時(shí)執(zhí)行  
  40.     };  
  41.     Extend(this.options, options || {});  
  42.   },  
  43.   Start: function() {  
  44.     clearTimeout(this._timer);  
  45.     //如果沒有數(shù)據(jù)就返回  
  46.     if(!this.List.length) return;  
  47.     //修正Index  
  48.     if(this.Index < 0 || this.Index >= this.List.length){ this.Index = 0; }  
  49.     //如果當(dāng)前索引不是顯示索引就設(shè)置顯示  
  50.     if(this._onIndex != this.Index){ this._onIndex = this.Index; this.Show(this.List[this.Index]); }  
  51.     //如果要自動(dòng)切換  
  52.     if(this.Auto){  
  53.         this._timer = setTimeout(Bind(thisfunction(){ this.Index++; this.Start(); }), this.Duration * 1000 + this.Pause);  
  54.     }  
  55.   },  
  56.   //顯示  
  57.   Show: function(list) {  
  58.     if(isIE){  
  59.         //設(shè)置變換參數(shù)  
  60.         with(this._img.filters.revealTrans){  
  61.             Transition = this.Transition; Duration = this.Duration; apply(); play();  
  62.         }  
  63.     }  
  64.     this._img.style.visibility = "";  
  65.     //設(shè)置圖片屬性  
  66.     this._img.src = list.img; this._img.alt = list.text;  
  67.     //設(shè)置鏈接  
  68.     !!list["url"] ? (this._a.href = list["url"]) : this._a.removeAttribute("href");  
  69.     //附加函數(shù)  
  70.     this.onShow();  
  71.   },  
  72.   //添加變換對(duì)象  
  73.   Add: function(sIimg, sText, sUrl) {  
  74.     this.List.push({ img: sIimg, text: sText, url: sUrl });  
  75.   },  
  76.   //停止  
  77.   Stop: function() {  
  78.     clearTimeout(this._timer);  
  79.   }  
  80. }; 

下載完整程序

ps:由于有些綠色版ie6會(huì)把濾鏡功能去掉,所以用這類ie6會(huì)看不到效果的,用正宗版本就可以正常瀏覽了。

原文鏈接:http://www.cnblogs.com/cloudgamer/archive/2008/05/23/1205642.html

【編輯推薦】

  1. JavaScript馬賽克遮罩圖片幻燈片切換類
  2. 對(duì)開發(fā)者非常有用的JavaScript庫
  3. 網(wǎng)易郵箱前端JavaScript編碼規(guī)范
  4. javascript解決圖片縮放及其優(yōu)化
  5. 看JavaScript如何實(shí)現(xiàn)頁面自適
責(zé)任編輯:張偉 來源: cloudgamer的博客
相關(guān)推薦

2010-09-30 14:11:41

JSIE6.0

2011-02-17 10:54:59

CSS3變換 簡單快捷

2010-08-19 10:56:55

JSIE6IE7

2009-09-03 16:50:35

C#鼠標(biāo)形狀

2009-03-29 10:02:31

IE8瀏覽器微軟

2024-05-30 08:23:37

ViewPager滑動(dòng)效果接口

2009-06-10 21:55:39

打開JavaScripIEFirefox

2010-08-17 15:04:37

JavaScriptDOM ready

2010-10-08 15:53:42

2010-08-19 15:24:52

IE6IE7IE8

2010-10-08 13:27:51

IE6pngJavaScript

2010-08-17 16:54:30

IE8JavaScript

2010-08-17 16:50:30

JSIE6IE8

2010-10-08 16:42:41

JavaScriptIE8

2010-08-20 13:34:12

IEFirefoxJavascript

2009-06-09 21:46:18

JavaScript差IEFirefox

2010-08-17 15:52:59

FirefoxIEJavaScript

2009-09-16 11:32:26

Javascript緩

2010-09-15 09:21:11

IEirefoxJavascript

2010-08-17 15:21:17

IEFirefoxHTML
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)