欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery實(shí)現(xiàn)的背景顏色漸變動(dòng)畫效果示例

 更新時(shí)間:2017年03月24日 10:09:17   作者:lvgaolong  
這篇文章主要介紹了jQuery實(shí)現(xiàn)的背景顏色漸變動(dòng)畫效果,涉及事件響應(yīng)及頁(yè)面元素屬性結(jié)合時(shí)間動(dòng)態(tài)變換的相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了jQuery實(shí)現(xiàn)的背景顏色漸變動(dòng)畫效果。分享給大家供大家參考,具體如下:

完整實(shí)例代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>背景顏色漸變</title>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
</head>
<body>
<input id="Button1" type="button" value="button" onclick="tggg()" />
<script>
  function tggg() {
    //$("#asd").css({ "background-color": "red" }).show().fadeOut(500);
    fadeColor(
    { r: 0, g: 255, b: 0 }, //star color
    {r: 255, g: 255, b: 255 }, //end color
    function (color) { document.getElementById("asd").style.backgroundColor = color; }, 1, 10);
  }
  //所有代碼的執(zhí)行時(shí)間只有24毫秒左右。
  function fadeColor(from, to, callback, duration, totalFrames) {
    //用一個(gè)函數(shù)來包裹setTimeout,根據(jù)幀數(shù)來確定延時(shí)
    function doTimeout(color, frame) {
      setTimeout(function () {
        try {
          callback(color);
        } catch (e) { JSLog.write(e); }
      }, (duration * 1000 / totalFrames) * frame);
      //總持續(xù)秒數(shù)/每秒幀數(shù)*當(dāng)前幀數(shù)=延時(shí)(秒),再乘以1000作為延時(shí)(毫秒)
    }
    // 整個(gè)漸變過程的持續(xù)時(shí)間,默認(rèn)為1秒
    var duration = duration || 1;
    // 總幀數(shù),默認(rèn)為持續(xù)秒數(shù)*15幀,也即每秒15幀
    var totalFrames = totalFrames || duration * 15; var r, g, b; var frame = 1;
    //在第0幀設(shè)置起始顏色
    doTimeout('rgb(' + from.r + ',' + from.g + ',' + from.b + ')', 0);
    //計(jì)算每次變化所需要改變的rgb值
    while (frame < totalFrames + 1) {
      r = Math.ceil(from.r * ((totalFrames - frame) / totalFrames) + to.r * (frame / totalFrames));
      g = Math.ceil(from.g * ((totalFrames - frame) / totalFrames) + to.g * (frame / totalFrames));
      b = Math.ceil(from.b * ((totalFrames - frame) / totalFrames) + to.b * (frame / totalFrames));
      // 調(diào)用本frame的doTimeout
      doTimeout('rgb(' + r + ',' + g + ',' + b + ')', frame); frame++;
    }
  }
</script>
<div style="width: 600px; height: 200px; border: 1px solid red;" id="asd">
  腳本之家歡迎各位光臨--http://www.dbjr.com.cn
</div>
</body>
</html>

PS:這里再為大家推薦幾款相關(guān)的顏色與特效工具供大家參考使用:

在線特效文字/彩色文字生成工具:
http://tools.jb51.net/aideddesign/colortext

在線彩虹文字/顏色漸變文字生成工具:
http://tools.jb51.net/aideddesign/txt_caihongzi

在線發(fā)光字生成工具:
http://tools.jb51.net/aideddesign/txt_faguangzi

仿古書排版文字豎排轉(zhuǎn)換工具:
http://tools.jb51.net/transcoding/shupai

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)

希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論