国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JavaScript淡入淡出漸變簡單實例

2019-11-20 11:54:11
字體:
來源:轉載
供稿:網(wǎng)友

本文實例講述了JavaScript淡入淡出漸變的實現(xiàn)方法。分享給大家供大家參考。具體如下:

這里介紹JavaScript淡入淡出的文字漸變例子,用js來控制div標簽元素實現(xiàn)漸變顯示,漸變隱藏,只要在那個標簽里的內容,都可以淡入淡出,代碼簡單,便于修改完善,前端設計者必備的網(wǎng)頁特效。

運行效果如下圖所示:

具體代碼如下:

<!DOCTYPE html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>js代碼控制元素簡單的淡入淡出效果</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 樣式版權所有.<br /></p></div></body></html>

希望本文所述對大家的javascript程序設計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 东源县| 广安市| 隆安县| 腾冲县| 周宁县| 台东市| 汾西县| 体育| 谷城县| 延安市| 遂昌县| 鄄城县| 五寨县| 平定县| 古丈县| 望奎县| 长阳| 井陉县| 筠连县| 马公市| 泰来县| 九龙坡区| 庆阳市| 商南县| 策勒县| 乌审旗| 宁安市| 永昌县| 瑞丽市| 定西市| 隆尧县| 金寨县| 民勤县| 太湖县| 惠水县| 江孜县| 蒙自县| 项城市| 鄂州市| 麻城市| 吉安市|