CSS3 transitions want to add a colour and fade it away

蹲街弑〆低调 提交于 2019-12-02 19:09:50

If you want something like a highlighting you may want to use CSS3 animations. They are not supported in older browsers. Check caniuse for this.

I've created a short example over here.

The highlight is called on clicking the link. Here is the CSS (without vendor-prefixes):

@keyframes highlight {
  0% {
    background: red
  }
  100% {
    background: none;
  }
}

#highlight:target {
  animation: highlight 1s;
}

One way to do it is to use the jQuery UI animate method, which extends the "normal" jQuery animate() to affect things like background-color.

Transitions like this is possible in css3 to, but obviously with not as wide browser support.

#maDiv {
   -webkit-transition:background-color 0.5s linear;
   -moz-transition: background-color 0.5s linear;
   -o-transition: background-color 0.5s linear;
   height: 20px;
   width: 20px;
   background:#000;
}

#maDiv:hover {
    background: #ff0;
}

That will fade the color when the user hovers the Div, and fade it back when mouse is out, over 0.5 seconds. For browser support details, see "css3 transition" here: http://www.html5rocks.com/en/features/presentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!