【问题标题】:Background image (transparent 24 bit PNG) fading issue in IE7 / IE8IE7 / IE8 中的背景图像(透明 24 位 PNG)褪色问题
【发布时间】:2011-10-28 07:43:33
【问题描述】:

如果用户在某个区域上方,我有一个内容元素会淡入。内容元素有一个背景图片,在 IE7/IE8 中只有一个大的黑色边框,而不是渐变色。

动画代码:

$(function(){
 $('#TopPackets').mouseenter(function(){
 jQuery('#TopPacketsContents').animate({
   opacity: 1,
   width: 'toggle'
 }, 307, function() {
 });
 });

 $('#TopPackets').mouseleave(function(){
   jQuery('#TopPacketsContents').hide('slow');
 });
});

现在是带有透明背景图片的内容元素:

<div id="TopPacketsContents" style="opacity: 1; display: none;">
    <!-- content -->
</div>

CSS:

#TopPacketsContents {
 background-image: url("../images/transparentBackground.png");
 background-repeat: no-repeat;
 height: 303px;
 width: 411px;
}

我尝试了this thread 的最高回答,但我无法设置背景:透明,因为我有背景图片!

我还尝试创建像 on this page 这样的包装元素。

HTML

<div id="TopPacketsContents">
    <div class="BackgroundImageWrapper">    
        <!-- content -->
    </div>
</div>

CSS

#TopPacketsContents {
    height: 303px;
    width: 411px;
}
.BackgroundImageWrapper {
    background-image: url("../images/TopPacketsBackground.png");
    background-repeat: no-repeat;
}

那么我有哪些选择?我只能为带有条件 cmets 的 IE7/IE8 使用非透明图像(看起来很难看)。我应该使用另一个动画吗?我应该使用悬停效果而不是动画(仅适用于 IE7/IE8)吗?还有其他修复方法吗?

【问题讨论】:

    标签: internet-explorer-8 internet-explorer-7 png transparent fade


    【解决方案1】:

    请参阅W3Schools on the opacity CSS 设置:

    为此的 CSS 是:opacity=1。

    IE8 及更早版本:filter:alpha(opacity=100)。

    【讨论】:

    • 你的意思是&lt;div id="TopPacketsContents" style="opacity: 1; display: none;"&gt;?这里的不透明度来自jQuery('#TopPacketsContents').animate({opacity: 1。现在我在这里删除了不透明度,因为它并没有真正使用。所以淡入有效,但淡出仍然有同样的问题。为什么 jQuery 不处理这个问题?我能做什么?
    • 我对 jQuery 不够熟悉,无法参与其中 - 我只是指出(假设 jQuery 使用 CSS) opacity 属性在 IE8 及更早版本中不起作用 -你需要使用过滤器:alpha(opacity=###)
    【解决方案2】:

    似乎我得到了这个工作。正如我所说,我删除了不透明度参数:

    <script type="text/javascript">
      $(function(){
        $('#TopPackets').mouseenter(function(){
        jQuery('#TopPacketsContents').animate({
          width: 'toggle'
        }, 307, function() {
        });
        });
    
        $('#TopPackets').mouseleave(function(){
          jQuery('#TopPacketsContents').hide('slow');
        });
      });
    </script>
    

    带有过滤器的新 CSS:

    #TopPacketsContents {
        width:411px;
        height:303px;
        background-image:url(../images/transparentBackground.png);
        background-repeat: no-repeat;
        /* IE hack */
        background:none\9; /* Targets IE only */
        filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="path/to/images/transparentBackground.png", sizingMethod="crop");
    }
    

    following answer 对我不起作用。我的解决方案来自this answer

    【讨论】:

    • 现在我发现这个解决方案不适用于我的子页面。尽管路径正确,但背景图像消失了..
    • 因为我没有找到解决方案,所以我从 hide 函数的参数中删除了 slow ...
    猜你喜欢
    • 2012-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-22
    • 1970-01-01
    • 2018-02-23
    • 2012-06-22
    • 2023-04-10
    相关资源
    最近更新 更多