动画径向渐变CSS3:从左向右移动?

时间:2014-10-03 08:58:38

标签: css css3 animation background radial-gradients

我希望使用径向渐变radial-gradient(circle, rgba(255,255,255,0.8) 0, rgba(255,255,255,0) 100%)为背景设置动画,将其从左向右移动

http://jsfiddle.net/odsb1fjh/2/

如何设置此径向渐变的动画以从div向左移动无限?

我已经尝试了动画和关键帧背景位置:左/右底部;但是不行。

2 个答案:

答案 0 :(得分:2)

试试这个



div
{
    position:absolute;
    width: 250px;
    height: 250px;
    background-color: black;
    background-image: url(http://frontend.lostboys.nl/presenations/Icons-fonts/img/chrome.png)
}

div:after
  {
     content:'';
      position:absolute;
      top:0;
      left:0;
      width:100%;
      height:100%;
     background-image: -webkit-radial-gradient(circle, rgba(255,255,255,0.8) 0, rgba(255,255,255,0) 100%);
    background-position: -1500px 0;
    background-repeat: no-repeat;
    -webkit-animation: animation 3s ease-in-out infinite;
}
@-webkit-keyframes animation {
    from {background-position: -250px 0;}
    to {background-position: 250px 0;}
}

<div></div>
&#13;
&#13;
&#13;

或者

&#13;
&#13;
div
{
    position:absolute;
    width: 250px;
    height: 250px;
    background-color: black;
    background-image: url(http://frontend.lostboys.nl/presenations/Icons-fonts/img/chrome.png);
    overflow:hidden
}

div:after
  {
     content:'';
      position:absolute;
      top:0;
      left:0;
      width:100%;
      height:100%;
     background-image: -webkit-radial-gradient(circle, rgba(255,255,255,0.8) 0, rgba(255,255,255,0) 100%);
    -webkit-animation: animation 3s ease-in-out infinite;
}
@-webkit-keyframes animation {
    from {left: -250px;}/**you can use translate3d(-250px,0,0)*/
    to {left: 250px;}/** translate3d(250px,0,0)*/
}
&#13;
<div></div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

“但是我们可以看到“正方形”的边界,其中轻的径向线在哪里”-为什么根本不使用径向背景,只需使用:

div

div {
  position: absolute;
  width: 250px;
  height: 250px;
  background-color: black;
  background-image: url(http://frontend.lostboys.nl/presenations/Icons-fonts/img/chrome.png);
  overflow: hidden;
}
div:after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgb(255, 255, 255);
  background: linear-gradient(
    90deg,
    rgba(250, 250, 250, 0) 0%,
    rgba(250, 250, 250, 0.5) 60%,
    rgba(250, 250, 250, 0) 100%
  );
  -webkit-animation: animation 3s ease-in-out infinite;
}
@-webkit-keyframes animation {
  from {
    left: -250px;
  }
  to {
    left: 250px;
  }
}
<div></div>