JavaScript淡入淡出漸變簡(jiǎn)單實(shí)例
本文實(shí)例講述了JavaScript淡入淡出漸變的實(shí)現(xiàn)方法。分享給大家供大家參考。具體如下:
這里介紹JavaScript淡入淡出的文字漸變例子,用js來(lái)控制div標(biāo)簽元素實(shí)現(xiàn)漸變顯示,漸變隱藏,只要在那個(gè)標(biāo)簽里的內(nèi)容,都可以淡入淡出,代碼簡(jiǎn)單,便于修改完善,前端設(shè)計(jì)者必備的網(wǎng)頁(yè)特效。
運(yùn)行效果如下圖所示:
具體代碼如下:
<!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>js代碼控制元素簡(jiǎn)單的淡入淡出效果</title> <style> * {margin:0; padding:0} body {font:12px Verdana,Arial; color:#777; background:#222} a {color:#999; text-decoration:none} a:hover {color:#bbb} #wrapper {width:500px; margin:75px auto} #buttons {height:35px} .button {border:1px solid #eee; background:#ccc; border-radius:3px; -moz-border-radius:3px; padding:4px 0 5px; width:245px; text-align:center; cursor:pointer; float:left; color:#555} .button:hover {border:1px solid #fff; background:#d9d9d9; color:#333} .floatright {float:right} #fade {opacity:0; filter:alpha(opacity='0') border-radius:3px; -moz-border-radius:3px; margin-bottom:10px; padding:9px 10px 0; height:26px; border:1px solid #548954; background:#355c33; color:#79af72; text-shadow:1px 1px #21341d} </style> <script type="text/javascript"> var fadeEffect=function(){ return{ init:function(id, flag, target){ this.elem = document.getElementById(id); clearInterval(this.elem.si); this.target = target ? target : flag ? 100 : 0; this.flag = flag || -1; this.alpha = this.elem.style.opacity ? parseFloat(this.elem.style.opacity) * 100 : 0; this.si = setInterval(function(){fadeEffect.tween()}, 20); }, tween:function(){ if(this.alpha == this.target){ clearInterval(this.si); }else{ var value = Math.round(this.alpha + ((this.target - this.alpha) * .05)) + (1 * this.flag); this.elem.style.opacity = value / 100; this.elem.style.filter = 'alpha(opacity=' + value + ')'; this.alpha = value } } } }(); </script> </head> <body> <div id="wrapper"> <div id="fade">JavaScript淡入淡出漸變例子</div> <div id="buttons"> <div class="button" onclick="fadeEffect.init('fade', 1)">Fade In</div> <div class="button floatright" onclick="fadeEffect.init('fade', 0)">Fade Out</div> </div> <p>For more information visit 樣式版權(quán)所有.<br /> </p> </div> </body> </html>
希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。
相關(guān)文章
JavaScript中textRange對(duì)象使用方法小結(jié)
這篇文章主要介紹了JavaScript中textRange對(duì)象使用方法小結(jié),需要的朋友可以參考下2015-03-03JavaScript實(shí)現(xiàn)多重繼承的方法分析
這篇文章主要介紹了JavaScript實(shí)現(xiàn)多重繼承的方法,結(jié)合實(shí)例形式詳細(xì)分析了javascript實(shí)現(xiàn)多重繼承的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下2018-01-01微信小程序使用ucharts在小程序中加入橫屏展示功能的全過(guò)程
這篇文章主要給大家介紹了關(guān)于微信小程序使用ucharts在小程序中加入橫屏展示功能的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用微信小程序具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-09-09JavaScript創(chuàng)建對(duì)象方法實(shí)例小結(jié)
這篇文章主要介紹了JavaScript創(chuàng)建對(duì)象方法,結(jié)合實(shí)例形式總結(jié)了javascript創(chuàng)建對(duì)象的基本原理及使用工廠(chǎng)模式、構(gòu)造函數(shù)模式與原型模式創(chuàng)建對(duì)象的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-09-09詳解uniapp頁(yè)面跳轉(zhuǎn)URL傳參大坑
本文主要介紹了詳解uniapp頁(yè)面跳轉(zhuǎn)URL傳參大坑,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03