1

如果之前已解决此问题,我们深表歉意。我学到了一些关于通过不透明度过渡淡化渐变的知识,但是我在淡化它们时遇到了麻烦。

我有一个 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;
}

我在这里缺少什么吗?或者不可能像这样过渡渐变的不透明度?

一如既往,感谢您提供的任何帮助和建议。我也愿意接受有关实现这一目标的更好方法的建议。

4

1 回答 1

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;
}

更新的演示

于 2013-10-30T19:33:00.200 回答