链接悬停时的淡入淡出效果?
在许多网站上,例如 http://www.clearleft.com,您会注意到,当链接将鼠标悬停在上方,它们会淡入不同的颜色,而不是立即切换(默认操作)。
我假设 JavaScript 是用来创建这种效果的,有人知道怎么做吗?
on many sites, such as http://www.clearleft.com, you'll notice that when the links are hovered over, they will fade into a different color as opposed to immediately switching, the default action.
I assume JavaScript is used to create this effect, does anyone know how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
现在人们只是使用 CSS3 过渡 因为它是比搞乱JS容易得多,浏览器支持相当好,而且只是装饰性的所以如果不起作用也没关系。
这样就可以完成工作:
您还可以通过用逗号分隔每个声明来使用不同的计时和缓动函数来转换特定的 CSS 属性,如下所示:
此处演示
Nowadays people are just using CSS3 transitions because it's a lot easier than messing with JS, browser support is reasonably good and it's merely cosmetic so it doesn't matter if it doesn't work.
Something like this gets the job done:
You can also transition specific CSS properties with different timings and easing functions by separating each declaration with a comma, like so:
Demo here
我知道在问题中你说“我假设 JavaScript 用于创建这种效果”,但 CSS 也可以使用,下面是一个例子。
CSS
HTML
这是一个 JSFIDDLE > 对于上面的代码!
Marcel 在其中一个答案中指出,您可以“转换多个 CSS 属性”,也可以使用“all”来使用所有 :hover 样式来影响元素,如下所示。
CSS
HTML
这是一个 JSFIDDLE > 对于“全部”示例!
I know in the question you state "I assume JavaScript is used to create this effect" but CSS can be used too, an example is below.
CSS
HTML
And here is a JSFIDDLE for the above code!
Marcel in one of the answers points out you can "transition multiple CSS properties" you can also use "all" to effect the element with all your :hover styles like below.
CSS
HTML
And here is a JSFIDDLE for the "all" example!
您可以使用 JQueryUI 执行此操作:
http://jsfiddle.net/dWCbk/
You can do this with JQueryUI:
http://jsfiddle.net/dWCbk/
在你的 CSS 中试试这个:
Try this in your css: