Skip to content

Instantly share code, notes, and snippets.

@vxhviet
Last active November 22, 2018 07:30
Show Gist options
  • Save vxhviet/9660d180ac90c9146bd449e6165360d7 to your computer and use it in GitHub Desktop.
Save vxhviet/9660d180ac90c9146bd449e6165360d7 to your computer and use it in GitHub Desktop.

How to animate box-shadow with silky smooth performance

SOURCE

SCSS version

@mixin animated-box-shadow($border-radius) {
  position: relative;
  cursor: pointer;
  background-color: $color-white;
  border-radius: $border-radius;
  box-shadow: 0 3px 15px rgba(0, 0, 0, 0.1);
  -webkit-transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
  transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);

  &::after {
    content: "";
    border-radius: $border-radius;
    position: absolute;
    z-index: -1;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    box-shadow: 0 5px 30px rgba(129,152,213, 0.3);
    opacity: 0;
    -webkit-transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
    transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
  }

  &:hover {
    -webkit-transform: scale(1.25, 1.25);
    transform: scale(1.25, 1.25);
    z-index: 2;
  }

  &:hover::after {
    opacity: 1;
  }
}

// Use like this
.box {
  height: 80px;
  width: 220px;
  padding: 19px;
  @include animated-box-shadow(10px);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment