我有一个div是一个链接,我的目标是当鼠标悬停在渐变淡入时,然后当鼠标离开该区域时淡出。
以下是指向相关CSS的jsfiddle的链接:http://jsfiddle.net/94KEZ/
这是div本身(不透明度设置为0):
nav .nav-right {
position: absolute;
right: 0;
top: 0;
width: 8%;
min-width: 110px;
height: 100%;
z-index: 8020;
cursor: pointer;
opacity: 0;
transition: opacity 2.75s;
-moz-transition: opacity 2.75s;
-webkit-transition: opacity 2.75s;
-o-transition: opacity 2.75s;
}
这是悬停的CSS(似乎工作正常......)
nav .nav-right:hover {
opacity: 1;
background: -moz-linear-gradient(left, rgba(255,242,0,0) 0%, rgba(255,252,0,0) 80%, rgba(255,255,0,0.8) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,242,0,0)), color-stop(80%,rgba(255,252,0,0)), color-stop(100%,rgba(255,255,0,0.8))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(255,242,0,0) 0%,rgba(255,252,0,0) 80%,rgba(255,255,0,0.8) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(255,242,0,0) 0%,rgba(255,252,0,0) 80%,rgba(255,255,0,0.8) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(255,242,0,0) 0%,rgba(255,252,0,0) 80%,rgba(255,255,0,0.8) 100%); /* IE10+ */
background: linear-gradient(to right, rgba(255,242,0,0) 0%,rgba(255,252,0,0) 80%,rgba(255,255,0,0.8) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00fff200', endColorstr='#ccffff00',GradientType=1 ); /* IE6-9 */
transition: opacity 5.75s;
-moz-transition: opacity 5.75s;
-webkit-transition: opacity 5.75s;
-o-transition: opacity 5.75s;
}
我也试过这个,但它似乎没有效果:
nav .nav-right:link {
opacity: 0;
transition: opacity 2.75s;
-moz-transition: opacity 2.75s;
-webkit-transition: opacity 2.75s;
-o-transition: opacity 2.75s;
}
我有什么东西在这里失踪吗?或者是不可能像这样过渡渐变的不透明度?
一如既往,感谢您提供的任何帮助和建议。我也愿意接受更好的方法来实现这一目标。
答案 0 :(得分:0)
是的,可以转换不透明度。
但要这样做,背景必须是恒定的;也就是说,它必须设置在基本状态:
CSS
nav .nav-right {
position: absolute;
right: 0;
top: 0;
width: 50%;
min-width: 110px;
height: 100%;
z-index: 8020;
cursor: pointer;
opacity: 0;
transition: opacity 2.75s;
-moz-transition: opacity 2.75s;
-webkit-transition: opacity 2.75s;
-o-transition: opacity 2.75s;
background: -moz-linear-gradient(left, rgba(255,242,0,0) 0%, rgba(255,252,0,0) 80%, rgba(255,255,0,0.8) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,242,0,0)), color-stop(80%,rgba(255,252,0,0)), color-stop(100%,rgba(255,255,0,0.8))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(255,242,0,0) 0%,rgba(255,252,0,0) 80%,rgba(255,255,0,0.8) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(255,242,0,0) 0%,rgba(255,252,0,0) 80%,rgba(255,255,0,0.8) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(255,242,0,0) 0%,rgba(255,252,0,0) 80%,rgba(255,255,0,0.8) 100%); /* IE10+ */
background: linear-gradient(to right, rgba(255,242,0,0) 0%,rgba(255,252,0,0) 80%,rgba(255,255,0,0.8) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00fff200', endColorstr='#ccffff00',GradientType=1 ); /* IE6-9 */
}
nav .nav-right:link {
opacity: 0;
transition: opacity 2.75s;
-moz-transition: opacity 2.75s;
-webkit-transition: opacity 2.75s;
-o-transition: opacity 2.75s;
}
nav .nav-right:hover {
opacity: 1;
transition: opacity 2.75s;
-moz-transition: opacity 2.75s;
-webkit-transition: opacity 2.75s;
-o-transition: opacity 2.75s;
}