在Javascript中闪烁一次文本

时间:2014-12-17 15:30:04

标签: javascript

我希望有一段文字在1秒内闪现一次。到目前为止有这个代码(我从这个网站收集了一些内容) - 我看过闪烁的功能,但我认为这是我最好的选择

function flashtext(ele, col) {
    var tmpColCheck = document.getElementById(ele).style.color;
    if (tmpColCheck === 'white') {
        document.getElementById(ele).style.color = col;
    } else {
        document.getElementById(ele).style.color = 'white';
    }
}
setInterval(function () {
    flashtext('tdOne', 'blue');
}, 1000);

2 个答案:

答案 0 :(得分:0)

<div id="example">Hello!</div>

$(document).ready(function() {
    var f = document.getElementById('example');
    setInterval(function() {
        f.style.display = (f.style.display == 'none' ? '' : 'none');
    }, 1000);

});

OR

如果要显式调用该函数,请使用此 -

function blink() {
   var f = document.getElementById('Foo');
   setInterval(function() {
      f.style.display = (f.style.display == 'none' ? '' : 'none');
   }, 1000);
}

答案 1 :(得分:0)

你可以单独用css做这个,我用它作为仪表板上数字时钟的冒号。见包括小提琴Here

      p {
        -moz-animation: mymove 1s ease infinite;
        -webkit-animation: mymove 1s ease infinite;
        -ms-animation: mymove 1s linear infinite;
        -o-animation: mymove 1s linear infinite;
        animation: mymove 1s linear infinite;
    }

    @keyframes mymove {  
    0% { opacity: 1.0; text-shadow: 0 0 20px #00c6ff; }
    50%{ opacity: 0; text-shadow: none;}
    100% { opacity: 1.0; text-shadow: 0 0 20px #00c6ff;}
}

@-webkit-keyframes mymove {
    0% { opacity: 1.0; text-shadow: 0 0 20px #00c6ff; }
    50%{ opacity: 0; text-shadow: none;}
    100% { opacity: 1.0; text-shadow: 0 0 20px #00c6ff; }
}