LESS: mixin to create Blink animation, passing @color -stops

别说谁变了你拦得住时间么 提交于 2019-12-11 07:15:40

问题


I wish to create a CSS animation that act like "Blink effect" using LESS. My purpose is to call a single mixin passing each time 2 @stop colors in order to get diffent color blink depending by css class of DOM element.

Currently I have the following HTML:

  <p class='blink'>
    Loading...
  </p>

  <p class='blink alert'>
    <big>WARNING!!!! Operation failed.</big>
  </p>

And here, LESS CODE:

.blink
{
  .animation-blink-mixin(@dark-green,@light-green);

  &.alert
  {
    .animation-blink-mixin(@dark-red,@light-red);
  }
}

ANIMATION MIXIN:

.animation-blink-mixin (@stop1, @stop2, @time:2s)
{
  animation:animation-blink @durata infinite;

  .steps()
  {
      0% { color:@stop1; }
     50% { color:@stop2; }
    100% { color:@stop1; }
  }

  @keyframes animation-blink { .steps(); }
}

My problem is that both DOM elements have the same "red color" animation, instead being one green2green and others red2red.

I understood that problem is in "animation name" that is always the same. Some suggestion to reach desired behaviour?

Thanks.


回答1:


Just set the animation name explicitly, e.g (codepen demo):

.blink {
    .animation-blink(blink, #080 + 200, #080);
    &.alert {
        .animation-blink(alert, #800, #800 + 200);
    }
}

.animation-blink(@name_, @color1, @color2, @time: .5s) {

    @name: ~"animation-blink-@{name_}";
    animation: @name @time ease-in-out infinite alternate;

    @keyframes @name {
        0% {color: @color1}
        to {color: @color2}
    }
}


来源:https://stackoverflow.com/questions/29142854/less-mixin-to-create-blink-animation-passing-color-stops

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!