是否可以有一个css转换,在悬停时淡出元素,但在鼠标离开时隐藏元素。
即悬停入=淡入0.5秒|悬停出=无淡入和即时
是的,您可以使用CSS3转换来实现这一点。从本质上讲,你的CSS应该是这样的:
#myLink {
opacity: 0;
}
#myLink:hover {
opacity: 1;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
这里有一个jsFiddle演示:Fiddle
是的,只需在:hover
而不是链接上设置转换-http://jsfiddle.net/spacebeers/X4ZqE/
(在Fiddle中,链接位于"结果"框的左上角)
#main-menu li a {
opacity: 0;
}
#main-menu li a:hover{
opacity: 1;
transition: opacity 0.5s ease-in; /* vendorless fallback */
-o-transition: opacity 0.5s ease-in; /* opera */
-ms-transition: opacity 0.5s ease-in; /* IE 10 betas, not needed in final build. */
-moz-transition: opacity 0.5s ease-in; /* Firefox */
-webkit-transition: opacity 0.5s ease-in; /*safari and chrome */
}