使用javascript闪烁多个文本
如何分别在经典asp中闪烁多个文本?我正试图在JavaScript中创建一个计时器。必须适用于IE、Firefox和Chrome。谢谢使用javascript闪烁多个文本,javascript,asp-classic,blink,Javascript,Asp Classic,Blink,如何分别在经典asp中闪烁多个文本?我正试图在JavaScript中创建一个计时器。必须适用于IE、Firefox和Chrome。谢谢 <script type="text/javascript"> var col = new String(); var x = 1; var y; function blink() { if (x % 2) { col = "rgb(255,0,0)";
<script type="text/javascript">
var col = new String();
var x = 1;
var y;
function blink() {
if (x % 2) {
col = "rgb(255,0,0)";
} else {
col = "rgb(255,255,255)";
}
aF.style.color = col;
aF1.style.color = col;
aF2.style.color = col;
aF3.style.color = col;
x++;
if (x > 2)
{ x = 1 };
setTimeout("blink()", 2000);
}
</script>
var col=新字符串();
var x=1;
变量y;
函数blink(){
如果(x%2){
col=“rgb(255,0,0)”;
}否则{
col=“rgb(255255)”;
}
aF.style.color=col;
aF1.style.color=col;
aF2.style.color=col;
aF3.style.color=col;
x++;
如果(x>2)
{x=1};
设置超时(“闪烁()”,2000);
}
您可以使用闭包的功能,我已经使用了您的代码来设置效果,但是它比更改字体颜色更好,您可以使用jquery fadeIn和fadeOut效果来获得更平滑的外观。字体效果只对文本部分有效,对整个元素无效。因此,最好是使用不透明度,或者使用jQuery
function blink(node)
{
var x = 1;
var timer;
function start_blink()
{
if(x%2==0)
col = "rgb(255,255,255)";
else
col = "rgb(255,0,0)";
node.style.color = col;
x++;
if (x > 2)
{ x = 1 };
}
function stop()
{
if(timer)
clearInterval(timer);
}
timer = setInterval(start_blink,2000);
return stop;
}
如何使用
var ele = document.getElementById('whomYouWantToBlink');
var stopper = blink(ele);
// to stop you can always call stopper() to stop the respective elements blinking effect