【问题标题】:how to do a fade in/out while moving down css animation如何在向下移动css动画时进行淡入/淡出
【发布时间】:2016-02-18 22:39:51
【问题描述】:

如何在使用 css 动画向下移动时使按钮在循环中淡入/淡出?到目前为止,我的淡入/淡出工作正常。但我不能让他们同时工作。

<div class="down-arrow"><button class="down-button animate-flicker" type="button">VVV</button></div>

@keyframes flickerAnimation {
    from {top:0px; opacity: 0; } 
    to {top:200px;}
}
@-o-keyframes flickerAnimation  {
    from {top:0px; opacity: 0; } 
    to {top:200px;}
}
@-moz-keyframes flickerAnimation  {
    from {top:0px; opacity: 0; } 
    to {top:200px;}
}
@-webkit-keyframes flickerAnimation {
    from {top:0px; opacity: 0; } 
    to {top:200px;}
}
.animate-flicker {
    animation: flickerAnimation 1s infinite alternate;
   -webkit-animation: flickerAnimation 1s infinite alternate;
   -moz-animation: flickerAnimation 1s infinite alternate;
   -o-animation: flickerAnimation 1s infinite alternate;   
}

https://jsfiddle.net/ywn9w5L9/3/

【问题讨论】:

    标签: css animation css-animations fading


    【解决方案1】:

    工作JSFiddle

    您只需将position 属性添加到现有css 中的animate-flicker 类。

    在下面检查我的代码 sn-p:

    @
    keyframes flickerAnimation {
      0 % {
        top: 0;
        opacity: 0;
      }
      100 % {
        top: 200px;
        opacity: 1;
      }
    }
    
    @ - o - keyframes flickerAnimation {
      from {
        top: 0px;
        opacity: 0;
      }
      to {
        top: 200px;
      }
    }
    
    @ - moz - keyframes flickerAnimation {
      from {
        top: 0px;
        opacity: 0;
      }
      to {
        top: 200px;
      }
    }
    
    @ - webkit - keyframes flickerAnimation {
      from {
        top: 0px;
        opacity: 0;
      }
      to {
        top: 200px;
      }
    }
    
    .animate - flicker {
      position: absolute;
      animation: flickerAnimation 1s infinite alternate; - webkit - animation: flickerAnimation 1s infinite alternate; - moz - animation: flickerAnimation 1s infinite alternate; - o - animation: flickerAnimation 1s infinite alternate;
    }
    <div class="down-arrow">
      <button class="down-button animate-flicker" type="button">VVV</button>
    </div>

    希望这会有所帮助。

    【讨论】:

    • 谢谢,但是在您的 jfiddle 上,按钮没有向下移动?我刚刚意识到我也没有设定位置,我认为必须是这样。但您的代码没有任何改变。
    • @Nick:你用的是哪个浏览器?小提琴在 chrome 中对我来说很好用。如果您在其他浏览器中测试它,您可能需要相应地更改 css,我只是更改了您的 css 以便在 chrome 上测试它。
    • 啊,是的,它确实可以在 chrome 中使用。我在firefox上,它不起作用。我怎样才能使它跨浏览器兼容?它似乎不适用于我这里的东西:jsfiddle.net/ywn9w5L9/24
    • @Nick :检查我最新更新的小提琴,代码是跨浏览器兼容的,只需将 position 属性添加到您的 animate-flicker 类,它应该可以在所有浏览器上正常工作。(我自己测试过,在 chrome、IE 和 FF 上运行良好)
    • @Nick :我的小提琴现在在不同的浏览器上是否按预期为您工作?
    猜你喜欢
    • 2019-02-11
    • 1970-01-01
    • 2015-07-01
    • 2016-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 2014-01-20
    相关资源
    最近更新 更多