在许多网站上,例如http://www.clearleft.com http://www.clearleft.com,您会注意到,当将鼠标悬停在链接上时,它们会淡入不同的颜色,而不是立即切换(默认操作)。
我假设 JavaScript 是用来创建这种效果的,有人知道怎么做吗?
现在人们只是利用CSS3 过渡 http://code.tutsplus.com/tutorials/css-fundamentals-css3-transitions--pre-10922因为它比与 JS 搞混 https://github.com/jquery/jquery-color,浏览器支持相当好,它只是装饰性的,所以如果它不起作用也没关系。
像这样的事情就可以完成工作:
a {
color:blue;
/* First we need to help some browsers along for this to work.
Just because a vendor prefix is there, doesn't mean it will
work in a browser made by that vendor either, it's just for
future-proofing purposes I guess. */
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;
/* ...and now for the proper property */
transition:.5s;
}
a:hover { color:red; }
您还可以通过用逗号分隔每个声明来使用不同的计时和缓动函数来转换特定的 CSS 属性,如下所示:
a {
color:blue; background:white;
-o-transition:color .2s ease-out, background 1s ease-in;
-ms-transition:color .2s ease-out, background 1s ease-in;
-moz-transition:color .2s ease-out, background 1s ease-in;
-webkit-transition:color .2s ease-out, background 1s ease-in;
/* ...and now override with proper CSS property */
transition:color .2s ease-out, background 1s ease-in;
}
a:hover { color:red; background:yellow; }
演示在这里 http://jsfiddle.net/Marcel/xejsM/52/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)