js+svg实现购物车数量增减数字动画效果代码

代码语言:html

所属分类:动画

代码描述:js+svg实现购物车数量增减数字动画效果代码

代码标签: js svg 购物车 数量 增减 数字 动画

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

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  
  
<style>
@import url("https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap");
body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  font-family: "Inter", sans-serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.icon-container {
  margin-bottom: 20px;
}

.bag {
  width: 64px;
  height: 64px;
  position: relative;
}
.bag.has-items .bag-body {
  fill: #2E6BD3;
  stroke: #2E6BD3;
}
.bag.has-items .bag-handle {
  transform: rotateX(0);
  stroke: #2E6BD3;
}
.bag.has-items #count {
  opacity: 1;
}
.bag.has-items.many-items .bag-body {
  transform: scaleX(1.14);
}
.bag svg {
  width: 100%;
  height: 100%;
  position: relative;
  transform: translate3d(0, 0, 0);
}
.bag svg .bag-handle {
  stroke: #B5B8BF;
  stroke-width: 2px;
  transform: rotateX(180deg);
  transform-origin: 16px 8px;
  transition: all 0.4s ease;
}
.bag svg .bag-body {
  fill: rgba(46, 107, 211, 0);
  stroke: #B5B8BF;
  stroke-width: 2;
  transition: all 0.2s ease;
  transform-origin: center;
}

#count {
  position: absolute;
  top: 22px;
  left:16px;
  width: 32px;
  text-align: center;
  font-size: 12px;
  font-family: inherit;
  font-weight: 800;
  line-height: 18px;
  color: white;
  opacity: 0;
  padding: 0;
}

.controls {
  width: 114px;
  position: fixed;
  bottom: 30px;
  display: flex;
  gap: 1px;
}
.controls button {
  width: 32px;
  height: 32px;
  line-height: 32px;
  font-size: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
  background: #eee;
  border: 0;
  user-select: none;
  color: black;
}
.controls button#decrease-btn {
  border-radius: 8px 0 0 8px;
}
.controls button#increase-btn {
  border-radius: 0 8px 8px 0;
}
.controls #counter {
  width: 48px;
  padding: 0;
  height: 32px;
  border: none;
  appearance: none;
  background: #eee;
  border-radius: 0;
  text-align: center;
}

.count-animate {
  animation: slide-up 0.4s ease;
}

.bag-animate {
  animation: bag-up 0.2s ease;
}

@keyframes slide-up {
  0% {
    transform: translateY(-120%) scale(1.2);
    opacity: 0;
  }
  50% {
    transform: translateY(2px) scale(0.8);
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}
@keyframes bag-up {
  0% {
    transform: scale(1);
  }
  60% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

input[type=number] {
  -moz-appearance: textfield;
}
</style>

  
</head>

<body translate="no">
  <!--https://x.com/benedikrok/sta.........完整代码请登录后点击上方下载按钮下载查看

网友评论0