Opacity Transition在Firefox和IE(以及其他?)中无效

时间:2013-11-01 21:24:11

标签: html css css3 opacity transition

对于我自己的网站,我向访客展示了几张照片。这些图片应位于opacity: 0.7;上,然后当使用transition: opacity 0.50s ease-in-out;将鼠标悬停在图片上时,图片应达到100%可见度。本段下的代码显示了我如何使其适用于Chrome。但即使它在Chrome中运行,它也无法在Firefox和Internet Explorer等浏览器中运行。你能帮我找出代码的哪一部分是错的吗?我已经添加了我能想到的所有跨浏览器不透明度支持!

.image.full2 {
    display: block;
    width: 100%;
    -moz-opacity: 0.7;
    -webkit-opacity: 0.7;
    opacity: 0.7;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
    filter: alpha(opacity=70);
    -khtml-opacity: 0.7;
    -moz-transition: opacity 0.50s ease-in-out;
    -webkit-transition: opacity 0.50s ease-in-out;
    -o-transition: opacity 0.50s ease-in-out;
    -ms-transition: opacity 0.50s ease-in-out;
    transition: opacity 0.50s ease-in-out;
}

.image.full2:hover {
    -webkit-opacity: 1.0;
    -moz-opacity: 1.0;
    opactiy: 1.0;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
    filter: alpha(opacity=100);
    -khtml-opacity: 1.0;
}

2 个答案:

答案 0 :(得分:1)

无需定义-webkit--moz-,因为几乎所有新浏览器都支持opacity属性。但是关于IE8或更早版本,你应该使用filter:alpha(opacity= x );,x应该是0到100%。也许它可以帮助你... :)

.image.full2 {
    display: block;
    width: 100%;
    opacity:0.7;
    filter:alpha(opacity=70); /* For IE8 and earlier */
    -moz-transition: opacity 0.50s ease-in-out;
    -webkit-transition: opacity 0.50s ease-in-out;
    -o-transition: opacity 0.50s ease-in-out;
    -ms-transition: opacity 0.50s ease-in-out;
    transition: opacity 0.50s ease-in-out;
}

.image.full2:hover {
    opacity:1;
    filter:alpha(opacity=100); /* For IE8 and earlier */
}

演示: http://jsfiddle.net/DcSnZ/1/

来源: http://www.w3schools.com/css/css_image_transparency.asp

答案 1 :(得分:0)

试试这个

.image.full2 {
  display: block;
  width: 100%;
  filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=70);
  opacity: 0.7;
  -webkit-transition: opacity 0.5s ease-in-out;
  -moz-transition: opacity 0.5s ease-in-out;
  -o-transition: opacity 0.5s ease-in-out;
  transition: opacity 0.5s ease-in-out;
}

.image.full2:hover {
  filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
  opacity: 1;
}