首页 文章

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

提问于
浏览
3

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

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

我该如何设置这个径向渐变的动画,从左到右移动div上的无限?

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

2 回答

  • 2

    “但我们可以看到”正方形“的边界,其中是光线径向” - 为什么要使用径向背景,只需使用:

    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>
    
  • 1

    试试这个

    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>
    

    或这个

    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)*/
    }
    
    <div></div>
    

相关问题