材料波纹样式背景动画

时间:2016-06-23 14:07:42

标签: css css-transitions

我找到了这个fiddle,但动画只有在我点击并按住时才有效。



#parent {
  height: 200px;
  width: 400px;
  background-color: lightgray;
}
#circle {
  background-image: url("http://upload.wikimedia.org/wikipedia/commons/0/0e/Ski_trail_rating_symbol-green_circle.svg");
  background-position: center center;
  background-repeat: no-repeat;
  background-size: 0 0;
  height: 200px;
  width: 400px;
  transition: .3s ease-in;
}
#parent:active #circle {
  background-size: 600px 600px;
}

<div id="parent">
  <div id="circle"></div>
</div>
&#13;
&#13;
&#13;

是否可以在页面加载时加载动画? 只需要动画中的背景加载类似于Android Lollipop ripple / Firefox OS for TV。

1 个答案:

答案 0 :(得分:3)

您可以使用CSS3 animation自动启动转换。

在此处详细了解animation

  1. https://css-tricks.com/almanac/properties/a/animation/
  2. https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Animations/Using_CSS_animations
  3. http://www.w3schools.com/css/css3_animations.asp
  4. 更新了小提琴: Fiddle

    <强>段:

    #parent {
      height: 200px;
      width: 400px;
      background-color: lightgray;
    }
    #circle {
      background-image: url("http://upload.wikimedia.org/wikipedia/commons/0/0e/Ski_trail_rating_symbol-green_circle.svg");
      background-position: center center;
      background-repeat: no-repeat;
      background-size: 0 0;
      height: 200px;
      width: 400px;
      /*transition: .3s ease-in;*/
      animation: example 1s ease-in infinite;
    }
    @keyframes example {
      0% {
        background-size: 0px 0px;
      }
      50% {
        background-size: 600px 600px;
      }
      100% {
        background-size: 0px 0px;
      }
    }
    <div id="parent">
      <div id="circle"></div>
    </div>