2012-02-16 28 views
0

基本的には、テキストを色分けして色を変えるだけです。テキストが青色から赤色、次にピンク色、紫色などのように点滅します。ありがとうございます。Javascript - 無地色の点滅

+0

です...どうして正確に問題がありますか?何を試しましたか? –

答えて

1

JavascriptではなくCSS3を使用できます。以下のサンプルは、赤から黄、緑、青、赤から赤に点滅します。モジラ、WebKitの、など(例えば-moz-アニメーション-moz-キーフレーム

index.htmlを

<!doctype html> 
<html> 
<head> 
    <title>Blinking Text</title>  
    <link rel="stylesheet" href="style.css" />  
</head> 
<body> 
    <div class="test">Text</div>  
    </body> 
</html> 

のstyle.cssために特定のベンダープレフィックスを追加することを忘れないでください

.test 
{ 
    font-size: 48pt; 
    animation: 2s blink steps(1) infinite; 
} 

@keyframes blink 
{ 
    0% { color: red; } 
    25% { color: yellow; } 
    50% { color: green; } 
    75% { color: blue; } 
    100% {color: red; } 
} 
0
function flashtext(ele,col) { 
var tmpColCheck = document.getElementById(ele).style.color; 

    if (tmpColCheck === 'silver') { 
    document.getElementById(ele).style.color = col; 
    } else { 
    document.getElementById(ele).style.color = 'silver'; 
    } 
} 

setInterval(function() { 
    flashtext('flashingtext','red'); 
    flashtext('flashingtext2','blue'); 
    flashtext('flashingtext3','green'); 
}, 500); //set an interval timer up to repeat the function