Simple JavaScript Animation for 1 Second to Highlight Text?

后端 未结 3 1367
小蘑菇
小蘑菇 2021-01-21 10:59

I searched by google but I found that much I can\'t overview it all, so I need your experience:

I need to highlight a text for 1 second. For example a simple \"blink\"-e

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 11:54

    var h = document.getElementById("highlight");
    window.onload = function () {
      // when the page loads, set the background to red
      h.style.backgroundColor = "#f00";
    
      // after 1 second (== 1000ms)
      window.setTimeout(function () {
        // ...revert this, use the original color
        h.style.backgroundColor = "";
      }, 1000);
    };
    

提交回复
热议问题