admin管理员组文章数量:1401362
i've few types of links on my website.
First is just simple link without any styles such as backgrounds. The second type of links are with background colors similar to buttons.
these both have hover color change effect which is acplished by CSS.
what i want is to animate that color change on hover, i want it to change smoothly.
is there any way to white a few line of code in master page of all other pages, so ever single link will animate its color change on hover?
Thanks in advance.
i've few types of links on my website.
First is just simple link without any styles such as backgrounds. The second type of links are with background colors similar to buttons.
these both have hover color change effect which is acplished by CSS.
what i want is to animate that color change on hover, i want it to change smoothly.
is there any way to white a few line of code in master page of all other pages, so ever single link will animate its color change on hover?
Thanks in advance.
Share Improve this question asked May 10, 2013 at 19:49 ZafarZafar 4391 gold badge12 silver badges20 bronze badges 1- See stackoverflow./questions/6008324/fade-effect-on-link-hover - the accepted answer shows how to achieve this with CSS transitions. – Paul Roub Commented May 10, 2013 at 19:55
3 Answers
Reset to default 5The simplest way to do this is to use CSS3 transitions on the background-color
property.
For example:
a {
background-color: blue;
-webkit-transition: background-color 1s;
-moz-transition: background-color 1s;
-o-transition: background-color 1s;
transition: background-color 1s;
}
a:hover {
background-color: red;
}
Note that this won't work in all browsers (e.g. IE8).
For more examples see https://developer.mozilla/en-US/docs/Web/Guide/CSS/Using_CSS_transitions
This is possible with jQuery (via 3rd party plugins that exist), OR css3 transitions.
Fiddle: http://jsfiddle/ZKXWg/
HTML
<a href="#">Hover me</a>
CSS
a,
a:hover {
-webkit-transition: color ease-in-out 800ms;
color: red;
}
a:hover {
color: blue;
}
I've only included the -webkit
vendor prefix, but applicable prefixes should be added/used.
Try using css3 transition property.
DEMO: http://jsfiddle/XjEC9/
a {
background-color: blue;
color: white;
transition-property: background-color, color;
transition-duration: 2s;
transition-timing-function: ease;
}
a:hover { color: red; background-color: green; }
本文标签: javascripthow to animate color of a link on hoverStack Overflow
版权声明:本文标题:javascript - how to animate color of a link on hover - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744293016a2599205.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论