css - 背景动画图像在 IE 和 Opera 浏览器中不起作用

标签 css html internet-explorer opera

这是我的CSS代码:

body {
        margin: 0;
        padding: 0;
    }
    #slideshow {
        position: relative;
        overflow: hidden;
        height: 100px;
    }
 #fixme
{

    height : 60px;
    position: relative;
    overflow : hidden;
}
    #animate-area { 
        height: 122%;
        width: 2538px;
        position: absolute;
        left: 0;
        top: -15px;
        background-image: url('http://s30.postimg.org/qnju89rkx/banner.png') ;
        -ms-animation: animatedBackground 40s linear infinite;
        -moz-animation: animatedBackground 40s linear infinite;
        -webkit-animation: animatedBackground 30s linear infinite;
    }
    /* Put your css in here */
    @keyframes animatedBackground {
        from { left: 0; }
        to { left: -1269px; }
    }
    @-webkit-keyframes animatedBackground {
        from { left: 0; }
        to { left: -1269px; }
    }
    @-moz-keyframes animatedBackground {
        from { left: 0; }
        to { left: -1269px; }
    }

这是 JSfiddle:http://jsfiddle.net/cz04c4nx/8/

现在它在 chrome 和 mozilla 浏览器中运行良好,但在 IE 和 Opera 中无法运行动画。

请问是什么原因?以及如何解决这个问题?

如有任何帮助,我们将不胜感激。提前致谢。

最佳答案

我不确定,但我想你忘记了什么。试试下面的代码。 将您的 #animate-area div 替换为:

 #animate-area { 
    height: 122%;
    width: 2538px;
    position: absolute;
    left: 0;
    top: -15px;
    background-image: url('http://s30.postimg.org/qnju89rkx/banner.png') ;
    animation: animatedBackground 40s linear infinite;
    -webkit-animation: animatedBackground 30s linear infinite;
    -moz-animation: animatedBackground 40s linear infinite;
    -o-animation: animatedBackground 40s linear infinite;
    -ms-animation: animatedBackground 40s linear infinite;  
}

不同之处在于动画标签。之后,在您的 CSS 底部添加以下内容。

    @-ms-keyframes animatedBackground {
    from { left: 0; }
    to { left: -1269px; }
}

  @-o-keyframes animatedBackground {
    from { left: 0; }
    to { left: -1269px; }
}

IE8 中的动画。将以下行复制到您网站的头部部分。如果用户浏览器低于 IE10,则将加载 jQuery 动画。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!--[if lt IE 10]>
<script> 

    $(document).ready(function(){
        $("#animate-area").animate({left:'-1269px'}, 40000, function() {});
    });
    </script> 
    <![endif]-->

它看起来并不完全像 CSS3 关键帧,但有一点替代。

关于css - 背景动画图像在 IE 和 Opera 浏览器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25615689/

相关文章:

html - 导航栏淡出问题

javascript - 如何用 CSS 或 JS 用矩形做 9 级

html - 如何在中心背景中制作跨度文本

css - IE 不使用重定向 URL 来解析相对 URL

html - IE10 字体适用于实时站点,但不适用于开发站点

javascript - 具有相同 id 的多个元素

html - 输入中心,标签在左上方

html - Bootstrap 链接按钮在移动设备上不起作用

jquery - 我是否需要将托管在 CDN 上的文件添加到 list 文件 HTML 5 list 文件中以进行离线缓存?

javascript - js 的替换方法的正则表达式不起作用