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

首頁 > 編程 > JavaScript > 正文

JS實現的顏色實時漸變效果完整實例

2019-11-20 10:20:47
字體:
來源:轉載
供稿:網友

本文實例講述了JS實現的顏色實時漸變效果。分享給大家供大家參考,具體如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head><title>無標題頁</title></head><body><div id="div1" style="font-size:36px;">我的閃爍文字 abc123</div><span id="span1"></span><script type="text/javascript">var begin = getRGB('#33FFAA');var end = getRGB('#FF0000');var curColor = getRGB('#33FFAA');var bo = true;var rate = getRate(begin, end);function blink(){ window.setInterval(function(){  curColor.r = getCur(begin.r, end.r, curColor.r, bo, rate.r);  curColor.g = getCur(begin.g, end.g, curColor.g, bo, rate.g);  curColor.b = getCur(begin.b, end.b, curColor.b, bo, rate.b);  document.getElementById('div1').style.color = getColor(curColor);  document.getElementById('span1').innerHTML = getColor(curColor);  if(curColor.r == begin.r && curColor.g == begin.g && curColor.b == begin.b)  {   bo = true;  }  if(curColor.r == end.r && curColor.g == end.g && curColor.b == end.b)  {   bo = false;  } } , 100);}function getCur(beginValue, endValue, curValue, bo, rateValue){ if(beginValue == endValue) {  return beginValue; } rateValue = beginValue < endValue ? rateValue : -rateValue; curValue += bo ? rateValue : -rateValue; if(curValue < Math.min(beginValue, endValue)) {  curValue = Math.min(beginValue, endValue); } if(curValue > Math.max(beginValue, endValue)) {  curValue = Math.max(beginValue, endValue); } return curValue;}function getRate(b, e){ var obj = new Object(); obj.r = Math.abs(b.r - e.r) / 5; obj.g = Math.abs(b.g - e.g) / 5; obj.b = Math.abs(b.b - e.b) / 5; return obj;}function getRGB(color){ var obj = new Object(); obj.r = parseInt(color.substr(1,2), 16); obj.g = parseInt(color.substr(3,2), 16); obj.b = parseInt(color.substr(5,2), 16); return obj;}function getColor(obj){ obj.r = Math.round(obj.r); obj.g = Math.round(obj.g); obj.b = Math.round(obj.b); var color = '#'; color += (obj.r < 16 ? '0':'') + obj.r.toString(16); color += (obj.g < 16 ? '0':'') + obj.g.toString(16); color += (obj.b < 16 ? '0':'') + obj.b.toString(16); return color;}blink();</script></body></html>

PS:這里再為大家推薦幾款本站的相關在線工具:

在線RGB、HEX顏色代碼生成器:
http://tools.VeVB.COm/color/rgb_color_generator

RGB顏色查詢對照表_顏色代碼表_顏色的英文名稱大全:
http://tools.VeVB.COm/color/jPicker

在線網頁調色板工具:
http://tools.VeVB.COm/color/color_picker

在線顏色選擇器工具/RGB顏色查詢對照表:
http://tools.VeVB.COm/color/colorpicker

更多關于JavaScript相關內容感興趣的讀者可查看本站專題:《JavaScript查找算法技巧總結》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調試技巧總結》、《JavaScript數據結構與算法技巧總結》、《JavaScript遍歷算法與技巧總結》及《JavaScript數學運算用法總結

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 内江市| 通海县| 澄迈县| 南昌市| 武平县| 靖远县| 荃湾区| 平谷区| 易门县| 高平市| 澎湖县| 临泉县| 桂林市| 大理市| 广宗县| 黄龙县| 宝清县| 洪洞县| 邯郸县| 博野县| 新竹市| 樟树市| 普兰店市| 根河市| 深圳市| 临武县| 正镶白旗| 南川市| 宿州市| 鲁山县| 通江县| 名山县| 南丹县| 吴桥县| 舟山市| 焉耆| 绥棱县| 读书| 盐津县| 桃园县| 磐石市|