css - 将 CSS 悬停动画转换为自动动画

标签 css css-transitions

我编写的代码使我的网站 Logo 闪耀。当鼠标悬停在 Logo 上时它可以工作,但我希望在加载网站时动画自动无限播放。我使用关键帧但不起作用,我很困惑。

我的 CSS 代码:

@import url(https://fonts.googleapis.com/css?family=Raleway);
html{
  font: .9em 'Raleway',sans-serif;
  height: 100%;
  text-align: center;
  background: radial-gradient(50% 0,rgba(255,255,255,.3),rgba(255,255,255,0)), deepskyblue;
  color: rgba(0,0,0,.6);
}
p a{
  color: rgba(0,0,0,.6);
}
.mask a{
  position: relative;
  display:block;
  width:150px;
  height: 64px;
  text-align:center;
  margin: 50px auto;
  background: ;
  -webkit-filter: drop-shadow(1px 1px 2px rgba(0,0,0,.5));
}
.mask a{
  background-position: -140px 0;
  
}
.mask a:hover,
.mask a:focus{
  background-position: 10px 0;
  /*change speed to see in slow motion*/
  transition: all 1s;
}
.mask a::after{
  content:'';
  position: absolute;
  pointer-events: none;
  top:0; left:0; right:0; bottom: 0;
  background: radial-gradient(0 0,circle farthest-side, rgba(255,255,255,0) 90%,rgba(255,255,255,.8) 98%,rgba(255,255,255,0) 100%) no-repeat;
  background: radial-gradient(circle farthest-side at 0 0, rgba(255,255,255,0) 90%,rgba(255,255,255,.8) 98%,rgba(255,255,255,0) 100%) no-repeat;
  background-position: inherit; 
  -webkit-mask: url('http://dev.iamvdo.me/newLogoCSS3create2.png') center;
  mask: url('#mask-firefox');
}
<div class="mask pseudo">
  <a href="http://css3create.com">
    <img src="http://dev.iamvdo.me/newLogoCSS3create2.png" alt="CSS3Create logo" />
  </a>
</div>


<svg height="0">
  <!-- THE mask -->
  <mask id="mask-firefox">
    <image width="150" height="64" xlink:href="http://dev.iamvdo.me/newLogoCSS3create2.png" filter="url(#filter)" /> 
  </mask>
  
  <!-- the filter to make the image white -->
  <filter id="filter">
    <feFlood flood-color="white" />
    <feComposite in2="SourceAlpha" operator="in" />
  </filter>
</svg>

最佳答案

请看这个例子,它声明了一个名为 shineFx 的动画,其迭代次数不定式

.mask a{
    position: relative;
    display:block;
    width:150px;
    height: 64px;
    text-align:center;
    margin: 50px auto;
    -webkit-filter: drop-shadow(1px 1px 2px rgba(0,0,0,.5));
    animation-name: shineFx;
    animation-duration: 3s;
    animation-timing-function: ease-out;
    animation-iteration-count: infinite;
}


@keyframes shineFx {
    from {background-position: -140px 0px;}
    to {background-position: 10px 0;}
}

关于css - 将 CSS 悬停动画转换为自动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44161251/

相关文章:

html - 如何让选择和文本字段在缩放父容器时内联显示和缩放?

javascript - 无法使鼠标滚轮停在上方/下方的 Div 处

html - 在 li 元素周围包裹 anchor 标记

css - 如何在 CSS 转换期间防止文本样式默认值

css3过渡缓和

动画填充模式 : forwards 后悬停时的 CSS 变换和过渡不起作用

使用 :after psuedo element displaying as a rectangle instead in IE8 的 CSS 三 Angular 形

android - 我的网站无法在 iPhone 上正确缩放

jquery - 由 jQuery 触发的过渡时 Chrome 闪烁

jquery - 单击时从中心向左动画 div