点赞收藏爱心动画效果

代码语言:html

所属分类:动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<style>
@charset "UTF-8";
*, *:before, *:after {
  position: relative;
  box-sizing: border-box;
}

:root {
  --color-bg: #FDF1F2;
  --color-heart: #EA442B;
  --easing: cubic-bezier(.7,0,.3,1);
  --duration: .5s;
}

html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.like-button {
  font-size: 35vmin;
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  border: none;
  border-radius: 50%;
  background: white;
  width: 1em;
  height: 1em;
  padding: 0;
  margin: 0;
  outline: none;
  z-index: 2;
  -webkit-transition: -webkit-transform var(--duration) var(--easing);
  transition: -webkit-transform var(--duration) var(--easing);
  transition: transform var(--duration) var(--easing);
  transition: transform var(--duration) var(--easing), -webkit-transform var(--duration) var(--easing);
  cursor: pointer;
}
.like-button:before {
  z-index: -1;
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  box-shadow: 0 0.3em 0.6em rgba(0, 0, 0, 0.3);
  border-radius: inherit;
  -webkit-transition: inherit;
  transition: inherit;
}
.like-button:after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #fff;
  border-radius: inherit;
  z-index: -1;
}
.like-button:active:before {
  -webkit-animation: depress-shadow var(--duration) var(--easing) both;
          animation: depress-shadow var(--duration) var(--easing) both;
}
.like-button:focus:after {
  -webkit-animation: depress var(--duration) var(--easing) both;
          animation: depress var(--duration) var(--easing) both;
}
@-webkit-keyframes depress {
  from, to {
    -webkit-transform: none;
            transform: none;
  }
  50% {
    -webkit-transform: translateY(5%) scale(0.9);
            transform: translateY(5%) scale(0.9);
  }
}
@keyframes depress {
  from, to {
    -webkit-transform: none;
            transform: none;
  }
  50% {
    -webkit-transform: translateY(5%) scale(0.9);
            transform: translateY(5%) scale(0.9);
  }
}
@-webkit-keyframes depress-shadow {
  from, to {
    -webkit-transform: none;
            transform: none;
  }
  50% {
    -webkit-transform: scale(0.5);
            transform: scale(0.5);
  }
}
@keyframes depress-shadow {
  from, to {
    -webkit-transform: none;
            transform: none;
  }
  50% {
    -webkit-transform: scale(0.5);
            transform: scale(0.5);
  }
}
.like-wrapper {
  display: grid;
  -webkit-box-align: center;
          align-items: center;
  -webkit-box-pack: center;
          justify-content: center;
  z-index: 1;
}
.like-wrapper > * {
  margin: auto;
  grid-area: 1 / 1;
}

.heart {
  width: .5em;
  height: .5em;
  display: block;
  -webkit-transform-origin: center 80%;
          transform-origin: center 80%;
}
.heart > path {
  stroke: var(--color-heart);
  stroke-width: 2;
  fill: transparent;
  -webkit-transition: fill var(--duration) var(--easing);
  transition: fill var(--duration) var(--easing);
}
.like-button:focus .heart > path {
  fill: var(--color-heart);
}
.like-button:focus .heart {
  -webkit-animation: heart-bounce var(--duration) var(--easing);
          animation: heart-bounce var(--duration) var(--easing);
}
@-webkit-keyframes heart-bounce {
  40% {
    -webkit-transform: scale(0.7);
            transform: scale(0.7);
  }
  0%, 80%, 100% {
    -webkit-transform: scale(1);
            transform: scale(1);
  }
}
@keyframes heart-bounce {
  40% {
    -webkit-transform: scale(0.7);
            transform: scale(0.7);
  }
  0%, 80%, 100% {
    -webkit-transform: scale(1);
            transform: scale(1);
  }
}
/* Added wrapper to prevent layout jank with resizing particles */
.particles {
  width: 1px;
  height: 1px;
}

.particle {
  position: absolute;
  top: 0;
  left: 0;
  height: .1em;
  width: .1em;
  border-radius: .05em;
  background-color: var(--color);
  --percentage: calc( var(--i) / var(--total-particles) );
  --Θ: calc( var(--percentage) * 1turn );
  -webkit-transform: translate(-50%, -50%) rotate(var(--Θ)) translateY(0) scaleY(0);.........完整代码请登录后点击上方下载按钮下载查看

网友评论0