zoukankan      html  css  js  c++  java
  • js 颜色渐变 PHP

    我的闪烁文字 abc123

    信息

    代码:

    <!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>

    下载:https://files.cnblogs.com/zjfree/HtmlFontColor.rar


    欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]
  • 相关阅读:
    高精度、大整数幂取模
    关于正则表达式
    003.android资源文件剖析(Resources)
    myBatis 基础测试 表关联关系配置 集合 测试
    Android应用开发学习笔记之播放音频
    移植一个开源点餐网到SAE平台上
    6.0RMB MP3所看到的……
    [读书笔记]设计原本[The Design of Design]
    递归 和 非递归 遍历二叉树
    Android应用开发学习笔记之播放视频
  • 原文地址:https://www.cnblogs.com/zjfree/p/2219044.html
Copyright © 2011-2022 走看看