【问题标题】:CSS Keyframes Slide not working on Background imageCSS关键帧幻灯片不适用于背景图像
【发布时间】:2015-12-11 07:30:50
【问题描述】:

使用第二个答案found here。我将我的图像组合成一个精灵,然后更新我的 CSS 以反映关键帧元素,就像提供的示例中一样。精灵图像(城堡)出现了,但没有出现幻灯片效果?我错过了什么?

示例 URL,主页中心元素:http://216.157.26.175/cookiedouglas/

这是我的 CSS:

.agentpress-pro-cookie  .home-featured .widget {
    /* background-color: rgba(255, 255, 255, 0.8); */
    background: url("http://216.157.26.175/cookiedouglas/wp-content/uploads/sites/58/2015/05/fort-myers-homes-for-sale.jpg");
    opacity: 0.95;
        content: '';
    /*    position: absolute;
        width: 400%;
        height: 100%; */
        z-index: -1;
     /*   background: url(http://placekitten.com/500/500/);  Image is 500px by 500px, but only 200px by 50px is showing. */
        animation: slide 3s infinite;
    }
    @keyframes slide {
        20% {
            left: 0;
        }
        40%, 60% {
            left: -50%;
        }
        80%, 100% {
            left: -100%;
        }
    }

【问题讨论】:

    标签: css


    【解决方案1】:

    使用浏览器(供应商)特定前缀。

    浏览器前缀用于添加可能不属于正式规范的新功能,并用于实现尚未最终确定的规范中的功能。

    CSS3 animation 是这些功能之一。它对不同的浏览器有部分支持。可以查看浏览器对 CSS3 动画的支持here

    从上面的链接可以看出,要使动画在 IE 和 Firefox 以外的浏览器上运行,您需要使用 -webkit- 前缀。

    此外,CSS left 属性仅适用于绝对定位的元素。

    所以你应该尝试这样的事情(阅读 sn-p 中添加的 cmets 以获得解释)

    /*visible portion of the larger 5120x680 pixel image*/
    .widget {
      width: 1024px;
      height: 680px;
      position: relative;
      overflow: hidden;
      border: 1px solid black;
    }
    
    .widget:before {
      content: '';
      position: absolute;
      /*needed for CSS left property to work*/
      width: 5120px;
      height: 680px;
      z-index: -1;
      /*ExampleImageSprite.jpg is a 5120x680 pixel image which is a combination of 5 individual 1024x680 pixel images*/
      background: url("https://dl.dropboxusercontent.com/u/192824325/00_sandbox/30150865/ExampleImageSprite.jpg");
      -webkit-animation: slide 10s infinite;
      animation: slide 10s infinite;
    }
    
    @-webkit-keyframes slide {
      0% {
        left: 0px;
      }
      20% {
        left: -1024px;
      }
      40% {
        left: -2048px;
      }
      60% {
        left: -3072px;
      }
      80% {
        left: -4096px;
      }
      100% {
        left: -5120px;
      }
    }
    @keyframes slide {
      0% {
        left: 0px;
      }
      20% {
        left: -1024px;
      }
      40% {
        left: -2048px;
      }
      60% {
        left: -3072px;
      }
      80% {
        left: -4096px;
      }
      100% {
        left: -5120px;
      }
    }
    <div class=widget></div>

    【讨论】:

    • 你能说得更具体点吗?我不明白。
    • 是的,我明白您所说的特定于浏览器的意思。不幸的是,它仍然没有动画。幻灯片 {} 元素如何准确地绑定回 .widget?
    • 我已经修复了代码 sn-p,在全屏窗口中查看。
    猜你喜欢
    • 2013-12-15
    • 2018-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-26
    • 2010-12-05
    • 1970-01-01
    相关资源
    最近更新 更多