HTML闪烁文本颜色

use*_*585 4 html javascript fonts colors

这是一个非常不寻常的要求,但..

反正有没有让一些文字每秒在2种颜色之间交替?

所以它似乎在说...红色和灰色之间闪烁?我不是指背景颜色,我的意思是实际的字体颜色.我假设它需要javascript或其他东西.

有没有简单的方法呢?

(无视它看起来很难看的事实)

UPDATE

我喜欢在我的页面上多次调用此函数,每个函数都传递不同的颜色以与GRAY交替

.

Bar*_*der 12

按您的要求:

    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
Run Code Online (Sandbox Code Playgroud)

JSFiddle:http://jsfiddle.net/neuroflux/rXVUh/14/


j08*_*691 7

这是使用纯JavaScript执行此操作的简单方法:

function flash() {
    var text = document.getElementById('foo');
    text.style.color = (text.style.color=='red') ? 'green':'red';
}
var clr = setInterval(flash, 1000);
Run Code Online (Sandbox Code Playgroud)

这将每秒在红色和绿色之间交替文本的颜色.jsFiddle例子.

这是另一个可以设置不同元素颜色的示例:

function flash(el, c1, c2) {
    var text = document.getElementById(el);
    text.style.color = (text.style.color == c2) ? c1 : c2;
}
var clr1 = setInterval(function() { flash('foo1', 'gray', 'red') }, 1000);
var clr2 = setInterval(function() { flash('foo2', 'gray', 'blue') }, 1000);
var clr3 = setInterval(function() { flash('foo3', 'gray', 'green') }, 1000);
Run Code Online (Sandbox Code Playgroud)

jsFiddle一起去吧.您传递要闪烁的元素的ID以及两种颜色之间的交替.