Уменьшить размер иконки во время анимации - PullRequest
1 голос
/ 21 апреля 2020

Я пытаюсь уменьшить размер контейнера значков (с 110px в 0% до 50px в 100%), когда анимация «slide-bck-top» находится в фокусе. Я пытался передать & __ icon-container {} внутри @keyframes, но это не сработало. вот мой файл s css:

.button {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border: none;
  height: 150px;
  width: 230px;
  background-color: transparent;
  outline: none;

  &__icon-container {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    color: color(white-0);
    background-color: color(blue-150);
    box-shadow: 0px 4px 4px color(black-0, 0.25);
    padding: 20px;
    cursor: pointer;
  }

  &__icon {
    fill: currentColor;
    width: 50px;
    height: 50px;
  }


  &:focus {
      animation: slide-bck-top 0.3s 1.5s cubic-bezier(0.47, 0, 0.745, 0.715) forwards;
  }

  @keyframes slide-bck-top {
    0% {
      transform: translateZ(0) translateY(0);
    }
    100% {
      transform: translateZ(-400px) translateY(-200px);
    }
  }
}

Ответы [ 2 ]

1 голос
/ 21 апреля 2020

Проблема в @keyframes не позволит вам передать селектор, так как он предназначен для свойств, а S CSS не скомпилирует его правильно вложенным. Это все равно что передать селектор в атрибуте color:.

Что вы могли бы сделать, это передать .button__icon-container в :focus и переместить @keyframes за пределы .button, поскольку @keyframes действительно является глобальным элементом области видимости, а SCSS / SASS будет по-прежнему все равно визуализируем его вне .button.

.button {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border: none;
  height: 150px;
  width: 230px;
  background-color: transparent;
  outline: none;

  &__icon-container {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    color: color(white-0);
    background-color: color(blue-150);
    box-shadow: 0px 4px 4px color(black-0, 0.25);
    padding: 20px;
    cursor: pointer;
  }

  &__icon {
    fill: currentColor;
    width: 50px;
    height: 50px;
  }


  &:focus {
      animation: slide-bck-top 0.3s 1.5s cubic-bezier(0.47, 0, 0.745, 0.715) forwards;

      .button__icon-container {
         animation: make-small 0.3s 1.5s cubic-bezier(0.47, 0, 0.745, 0.715) forwards;
    }
  }
}


@keyframes slide-bck-top {
    0% {
      transform: translateZ(0) translateY(0);
    }
    100% {
      transform: translateZ(-400px) translateY(-200px);
    }
  }

  @keyframes make-small {
    0% {
      width: 110px;
      height: 110px;
    }
    100% {
      width: 50px;
      height: 50px;
    }
  }

Это компилируется в это:

.button {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border: none;
  height: 150px;
  width: 230px;
  background-color: transparent;
  outline: none;
}
.button__icon-container {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  color: color(white-0);
  background-color: color(blue-150);
  box-shadow: 0px 4px 4px color(black-0, 0.25);
  padding: 20px;
  cursor: pointer;
}
.button__icon {
  fill: currentColor;
  width: 50px;
  height: 50px;
}
.button:focus {
  animation: slide-bck-top 0.3s 1.5s cubic-bezier(0.47, 0, 0.745, 0.715) forwards;
}
.button:focus .button__icon-container {
  animation: make-small 0.3s 1.5s cubic-bezier(0.47, 0, 0.745, 0.715) forwards;
}

@keyframes slide-bck-top {
  0% {
    transform: translateZ(0) translateY(0);
  }
  100% {
    transform: translateZ(-400px) translateY(-200px);
  }
}
@keyframes make-small {
  0% {
    width: 110px;
    height: 110px;
  }
  100% {
    width: 50px;
    height: 50px;
  }
}
0 голосов
/ 21 апреля 2020

попробуйте использовать свойство max-height.

  @keyframes slide-bck-top {
    0% {
      transform: translateZ(0) translateY(0);
      max-height:110px;
    }
    100% {
      transform: translateZ(-400px) translateY(-200px);
      max-height:50px
    }
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...