最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Having a html element flash a background color and fade to another - Stack Overflow

programmeradmin1浏览0评论

I'm looking for a light weight solution to have an HTML element like a div or an li flash one background color, like solid green, then fade to another color over some time period like fading to white over 3 secs.

I don't want to include some massive library like jquery, and I only need this to work on Firefox, the most light weight the solution the better!

I know I could do this with javascript fairly easily, but it won't be very lightweight and I figure there must be some way to do this with CSS, that would be the ideal solution in my opinion.

I'm looking for a light weight solution to have an HTML element like a div or an li flash one background color, like solid green, then fade to another color over some time period like fading to white over 3 secs.

I don't want to include some massive library like jquery, and I only need this to work on Firefox, the most light weight the solution the better!

I know I could do this with javascript fairly easily, but it won't be very lightweight and I figure there must be some way to do this with CSS, that would be the ideal solution in my opinion.

Share Improve this question asked Jul 28, 2013 at 22:09 erikvolderikvold 16.6k11 gold badges58 silver badges101 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 6

Use an animation:

#flashMe {
  height: 500px;
  width: 500px;
  background-color: black;
      
  animation: flash 3s forwards linear normal;
}

@keyframes flash {
  0% {
     background-color: black;
  }
  4% {
    background-color: green;
  }
  100% {
    background-color: red;
  }
}
<div id="flashMe"></div>

You could take a look at CSS3 Animations. I am not that good with CSS3 so I can't provide any solution but afaik CSS3 can do stuff like this.

http://www.w3schools./css3/css3_animations.asp

发布评论

评论列表(0)

  1. 暂无评论