如何分别在经典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)";
} 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>
答案 0 :(得分:1)
你可以使用闭包的力量,我已经用你的代码来设置你的效果但是它更好而不是字体颜色变化你使用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