0

如何分别在经典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>
4

1 回答 1

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
于 2014-01-22T06:06:47.260 回答