Firefox:过渡占位符不透明度

3

我希望通过过渡使输入占位符在聚焦时平滑淡出,但无法在Firefox中实现。

<input type="text" placeholder="some cool text"/>

input:focus::-moz-placeholder {
    opacity: 0.1;
}
input::-moz-placeholder {
    opacity: 1;
    transition: opacity 1s;
}
input::-moz-placeholder {
    opacity: 1;
}
input:focus::-webkit-input-placeholder {
     opacity: 0.1;
}

代码片段

在Chrome中工作良好,但在FF中不起作用。 占位符在焦点上按预期更改不透明度,但1秒的过渡效果不出现。它在IE中肯定也不起作用。

编辑:显然这是最新版FF(20.0.1)中的一个错误。

2个回答

2
像这样做怎么样?不要使用 opacity,而是切换颜色阴影。 演示
<input type="text" placeholder="some cool text"/>

input[type=text]:-moz-placeholder {
color: #000;
transition: color 1s;
}

input[type=text]:focus:-moz-placeholder {
    color: #aaa;
}

input[type=text]::-webkit-input-placeholder {
    color: #000;
    transition: color 1s;
}

input[type=text]:focus::-webkit-input-placeholder {
    color: #aaa;
}

如果您愿意,当然可以使用opacity,但您可以自己查看结果,并决定哪种方法更适合您,透明度演示

注意:使用::-moz-placeholder来支持+19版本


嗯,我不知道发生了什么。我正在Mac上进行测试,如果有任何区别的话。 - btevfik
1
@btevfik 为了支持 Firefox +19,您需要使用 ::,即 ::-moz-placeholder - Mr. Alien
不,这两种方法都会改变不透明度,但不带有过渡效果。(使用了最新的 FF 版本) - skyisred
好的,我可能有点插不上话,但是Windows和Mac的Firefox有区别吗? - AdityaSaxena
@skyisred 它正在运行,请安装旧版本并检查一下。 - Mr. Alien
显示剩余7条评论

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接