HOME  >>>  HTML整理ノート  >>> DHTML -- 基本編   応用編

グラデーション文字列

DYNAMIC HTML



 

Sample Source......................................................................>>>

<script language="JavaScript"><!--
function Gra(n){
var msg ="DYNAMIC HTML";
var str = "";
var c = 0;    //色のRGB値(10進数)
for(i=0;i<msg.length;i++){
    cc = c.toString(16);    //16進数に変換
    if(cc.length<2)cc = "0"+cc; //1桁の場合は0を付ける
   
    if(n == 1)str += "<font color='#"+cc+cc+cc+"'>"
        + msg.substring(i,i+1) + "</font>";
    if(n == 2)str += "<font color='#ff"+cc+cc+"'>"
        + msg.substring(i,i+1) + "</font>";
    if(n == 3)str += "<font color='#"+cc+cc+"ff'>"
        + msg.substring(i,i+1) + "</font>";
    if(n == 4)str += "<font color='#"+cc+"ff"+cc+"'>"
        + msg.substring(i,i+1) + "</font>";
    if(n == 5)str += "<font color='#ffff"+cc+"'>"
        + msg.substring(i,i+1) + "</font>";
    if(n == 6)str += "<font color='#ff"+cc+"ff'>"
        + msg.substring(i,i+1) + "</font>";
    if(n == 7)str += "<font color='#"+cc+"ffff'>"
        + msg.substring(i,i+1) + "</font>";

    c += 21;    //色の値(10進数)を21増加さす
}
dv.innerHTML = str;
}
//--></script>
</head>

<body>
<div id="dv" style="width:430;background-color:gray;
    font:40pt 'Arial Black';text-align:center">
    DYNAMIC HTML
</div>

<button onclick="Gra(1);">黒のグラデーション</button>
<button onclick="Gra(2);">赤のグラデーション</button><br>
<button onclick="Gra(3);">青のグラデーション</button>
<button onclick="Gra(4);">緑のグラデーション</button><br>
<button onclick="Gra(5);">黄色のグラデーション</button>
<button onclick="Gra(6);">紫のグラデーション</button>
<button onclick="Gra(7);">水色のグラデーション</button>


end(最終更新:12/11/16)