簡體   English   中英

使用javascript閃爍多個文本

[英]blink multiple text using javascript

如何分別在經典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>

您可以使用閉包的強大功能,我已經使用您的代碼來設置效果,但是使用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM