1

Как здесь, но не при наведении а через время

<a href="#" class="icon">Кнопка</a>
.icon {
  position: relative;
  overflow: hidden;
  width: 50px;
  height: 50px;
  display: inline-block;

  margin: 25px 0 25px 25px;
  border-radius: 5px;
  color: #fff;
  text-decoration: none;
  text-align: center;
  line-height: 50px;
  font-size: 12px;
  font-family: sans-serif;
}

.icon:nth-child(1) { background: cornflowerblue; }
.icon:after {
    content: "";
    height: 200%;
    left: -230%;
    opacity: 0;
    position: absolute;
    top: -20%;
    transform: rotate(-30deg);
    width: 200%;

  background: rgba(255, 255, 255, 0.13);
  background: linear-gradient(
    to right, 
    rgba(255, 255, 255, 0.13) 0%,
    rgba(255, 255, 255, 0.13) 77%,
    rgba(255, 255, 255, 0.5) 92%,
    rgba(255, 255, 255, 0.0) 100%
  );
}

/* Hover state - trigger effect */

.icon:hover:after {
    left: -50%;
    opacity: 1;
    top: -50%;
    transition-duration: 0.7s, 0.7s, 0.15s;
    transition-property: left, top, opacity;
    transition-timing-function: ease;
}

/* Active state */

.icon:active:after {
  opacity: 0;
}

https://jsfiddle.net/fr7goymh/4/

1 ответ 1

2

Так можно сделать при помощи keyframe animation:

 @keyframes anim {
   0% {
      left: -230%;
      top: -20%;
  }
  50% {
    left: -50%;
    top: -50%;
  }
  100% {
    left: -230%;
    top: -20%;
  }
}

При наведении:

.icon:hover:after {
     animation: anim 2s infinite; 
 }  

.icon {
  position: relative;
  overflow: hidden;
  width: 50px;
  height: 50px;
  display: inline-block;
  margin: 25px 0 25px 25px;
  border-radius: 5px;
  color: #fff;
  text-decoration: none;
  text-align: center;
  line-height: 50px;
  font-size: 12px;
  font-family: sans-serif;
}

.icon:nth-child(1) { background: cornflowerblue; }

.icon:after {
    content: "";
    height: 200%;
    left: -230%;
    opacity: 0;
    position: absolute;
    top: -20%;
    transform: rotate(-30deg);
    width: 200%;
  opacity: 1;
  background: rgba(255, 255, 255, 0.13);
  background: linear-gradient(
    to right, 
    rgba(255, 255, 255, 0.13) 0%,
    rgba(255, 255, 255, 0.13) 77%,
    rgba(255, 255, 255, 0.5) 92%,
    rgba(255, 255, 255, 0.0) 100%
  );
}

/* Hover state - trigger effect */

.icon:hover:after {
 animation: anim 2s infinite;
}

/* Active state */

.icon:active:after {
  opacity: 0;
}


@keyframes anim {
  0% {
     left: -230%;
     top: -20%;
  }
  50% {
    left: -50%;
    top: -50%;
  }
   100% {
     left: -230%;
     top: -20%;
  }
}
<a href="#" class="icon">Кнопка</a>

На постоянной основе:

.icon:after {
   ....
   animation: anim 2s infinite;
}

.icon {
  position: relative;
  overflow: hidden;
  width: 50px;
  height: 50px;
  display: inline-block;
  margin: 25px 0 25px 25px;
  border-radius: 5px;
  color: #fff;
  text-decoration: none;
  text-align: center;
  line-height: 50px;
  font-size: 12px;
  font-family: sans-serif;
}

.icon:nth-child(1) { background: cornflowerblue; }

.icon:after {
    content: "";
    height: 200%;
    left: -230%;
    opacity: 0;
    position: absolute;
    top: -20%;
    transform: rotate(-30deg);
    width: 200%;
  opacity: 1;
  background: rgba(255, 255, 255, 0.13);
  background: linear-gradient(
    to right, 
    rgba(255, 255, 255, 0.13) 0%,
    rgba(255, 255, 255, 0.13) 77%,
    rgba(255, 255, 255, 0.5) 92%,
    rgba(255, 255, 255, 0.0) 100%
  );
   animation: anim 2s infinite;
}


.icon:active:after {
  opacity: 0;
}


@keyframes anim {
  0% {
     left: -230%;
     top: -20%;
  }
  50% {
    left: -50%;
    top: -50%;
  }
   100% {
     left: -230%;
     top: -20%;
  }
}
<a href="#" class="icon">Кнопка</a>

8
  • 1
    @Alexander обновил ответ 16 мар 2019 в 7:54
  • 1
    А почему туда-обратно?
    – Qwertiy
    16 мар 2019 в 8:50
  • 1
    И вообще, поворачивать псевдоэмент с градиентом - это как-то странно...
    – Qwertiy
    16 мар 2019 в 8:50
  • 1
    @Alexander правильно - так как Вам надо 16 мар 2019 в 9:08
  • 1
    @Alexander, что-то типа linear-gradient(30deg, ...), но надо проверять, возможно -30deg или ещё что-то. Ну и числа вроде изменятся.
    – Qwertiy
    16 мар 2019 в 9:28

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.