背景图片CSS动画

时间:2017-10-23 07:48:15

标签: css animation transform

我们在Safari中特别在以下演示中面临此空白问题(http://take.ms/xuQJS)?

演示:https://codepen.io/anon/pen/WZBeMG

我们无法找到问题的根源,我们非常感谢您的帮助。考虑到我们只想在动画中使用transform

1 个答案:

答案 0 :(得分:5)

您的.scroll太短了。试试.scroll {width: 200%}。现在你有宽度100%并且你移动你的元素-500px,所以会有间隙。

*, *:before, *:after {
  box-sizing: border-box;
}

@-webkit-keyframes scrollGood {
  0% {
    -webkit-transform: translate3d(0, 0, 0);
            transform: translate3d(0, 0, 0);
  }
  100% {
    -webkit-transform: translate3d(-500px, 0, 0);
            transform: translate3d(-500px, 0, 0);
  }
}
@keyframes scrollGood {
  0% {
    -webkit-transform: translate3d(0, 0, 0);
            transform: translate3d(0, 0, 0);
  }
  100% {
    -webkit-transform: translate3d(-500px, 0, 0);
            transform: translate3d(-500px, 0, 0);
  }
}
.pen {
  background-color: blue;
  position: absolute;
  top: 0px;
  left: 0px;
  height: 100%;
  width: 100%;
}

.panel {
  padding: 3rem;
  height: 100%;
}

.bottom {
  background-color: #31CC70;
  overflow: hidden;
  position: relative;
}
.bottom .scroll {
  background-image: url(http://scarbroughstudios.com/img/codepen.svg);
  background-position: center center;
  background-size: 500px;
  position: absolute;
  top: 0px;
  left: 0px;
  height: 400%;
  width: 200%;
  z-index: 1;
  -webkit-animation: scrollGood 5s linear infinite;
  animation: scrollGood 5s linear infinite;
}
<section class="pen">
<div class="panel bottom">
  <div class="scroll"></div>
</div>
</section>