js+svg+css实现带表情的拖动滑块评分效果代码

代码语言:html

所属分类:星级评分

代码描述:js+svg+css实现带表情的拖动滑块评分效果代码

代码标签: js svg css 表情 拖动 滑块 评分

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

<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
    @import url("https://fonts.googleapis.com/css2?family=Raleway:wght@200;300;400;500&display=swap");

:root {
  --body-color: #ebf4ff;
  --bad-color: #ff5722;
  --ok-color: #ff9800;
  --good-color: #36d896;
  --great-color: #3f51b5;
  --track-color: #eaeef4;
}

* {
  padding: 0;
  margin: 0;
}

body {
  background: var(--body-color);
  height: 100vh;
  align-items: center;
  display: flex;
  font-family: "Raleway", sans-serif;
}

.card {
  height: 160px;
  width: 530px;
  background: #fff;
  display: flex;
  margin: auto;
  position: relative;
  border-radius: 20px;
  box-shadow: 0px 2px 10px -10px #2f2f2f;
  flex-direction: column;
  padding: 30px;
  box-sizing: border-box;
}

.card .row {
  margin-top: 30px;
  display: flex;
}

.card p {
  font-size: 18px;
  font-weight: 700;
  color: var(--great-color);
}

.icon {
  height: 40px;
  width: 40px;
  position: relative;
}

.icon svg {
  height: 100%;
  width: 100%;
  position: absolute;
}

.range {
  position: relative;
  width: 360px;
  height: 17px;
  left: 40px;
  top: 10px;
}

.range svg {
  width: 100%;
  height: 100%;
}

.range svg path {
  transition: linear 0.5s;
}

input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  position: absolute;
  left: 0;
  top: 50%;
  margin: 0;
  padding: 0;
  transform: translateY(-50%);
  background: none;
  transition: linear 0.5s;
}

input[type="range"]:focus {
  outline: 0;
}

input[type="range"]::-webkit-slider-thumb {
  width: 26px;
  -webkit-appearance: none;
  height: 26px;
  cursor: pointer;
  border-radius: 50%;
  border: 6px solid #fff;
  box-shadow: 0px 0px 6px 0px #ccc;
  z-index: 2;
  position: relative;
  margin-left: 3px;
  margin-top: -3px;
}

.range.bad svg path#path-ok,
.range.bad svg path#path-good,
.range.bad svg path#path-great {
  fill: var(--track-color);
}

.icon svg#icon-bad path {
  fill: var(--bad-color);
}

.icon svg#icon-ok path {
  fill: var(--ok-color);
}

.icon svg#icon-good path {
  fill: var(--good-color);
}

.icon svg#icon-great path {
  fill: var(--great-color);
}

.row.bad input[type="range"]::-webkit-slider-thumb {
  background: var(--bad-color);
}

.row.ok input[type="range"]::-webkit-slider-thumb {
  background: var(--ok-color);
}

.row.good input[type="range"]::-webkit-slider-thumb {
  background: var(--good-color);
}

.row.great input[type="range"]::-webkit-slider-thumb {
  background: var(--great-color);
}

.row .icon svg {
  display: none;
}

.row.bad .icon svg#icon-bad,
.row.ok .icon svg#icon-ok,
.row.good .icon svg#icon-good,
.row.great .icon svg#icon-great {
  display: block;
  animation: heartBeat 1s;
}

@-webkit-keyframes heartBeat {
  0% {
    -webkit-transform: scale(1);
    transform: scale(1);
  }

  14% {
    -webkit-transform: scale(1.3);
    transform: scale(1.3);
  }

  28% {
    -webkit-transform: scale(1);
    transform: scale(1);
  }

  42% {
    -webkit-transform: scale(1.3);
    transform: scale(1.3);
  }

  70% {
    -webkit-transform: scale(1);
    transform: scale(1);
  }
}

@keyframes heartBeat {
  0% {
    -webkit-transform: scale(1);
    transform: scale(1);
  }

  14% {
    -webkit-transform: scale(1.3);
    transform: scale(1.3);
  }

  28% {
    -webkit-transform: scale(1);
    transform: scale(1);
  }

  42% {
    -webkit-transform: scale(1.3);
    transform: scale(1.3);
  }

  70% {
    -webkit-transform: scale(1);
    transform: scale(1);
  }
}

.animate__heartBeat {
  -webkit-animation-duration: 1.3s;
  animation-duration: 1.3s;
  -webkit-animation-duration: calc(var(--animate-duration) * 1.3);
  animation-duration: calc(var(--animate-duration) * 1.3);
  -webkit-animation-name: heartBeat;
  animation-name: heartBeat;
  -webkit-animation-timing-function: ease-in-out;
  animation-timing-function: ease-in-out;
}

.range:after {
  content: "";
  position: absolute;
  box-shadow: 99px 31px 0px 1px var(--track-color),
    183px 31px 0px 1px var(--track-color), 267px 31px 0px 1px var(--track-color),
    351px 31px 0px 1px var(--track-color);
  left: 0;
  height: 6px;
}

.row.bad .range:after {
  box-shadow: 99px 31px 0px 1px var(--bad-color),
    183px 31px 0px 1px var(--track-color), 267px 31px 0px 1px var(--track-color),
    351px 31px 0px 1px var(--track-color);
}

.row.ok .range:after {
  box-shadow: 99px 31px 0px 1px var(--track-color),
    183px 31px 0px 1px var(--ok-color), 267px 31px 0px 1px var(--track-color),
    351px 31px 0px 1px var(--track-color);
}

.row.good .range:after {
  box-shadow: 99px 31px 0px 1px var(--track-color),
    183px 31px 0px 1px var(--track-color), 267px 31px 0px 1px var(--good-color),
    351px 31px 0px 1px var(--track-color);
}

.row.great .range:after {
  box-shadow: 99px 31px 0px 1px var(--track-color),
    183px 31px 0px 1px var(--track-color), 267px 31px 0px 1px var(--track-color),
    351px 31px 0px 1px var(--great-color);
}
</style>

</head>
<body>

<div class="card">
  <p>您的评价</p>
  <div class="row">
    <div class="icon">
      <svg id="icon-bad" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 103.696 103.695">
        <path d="M75.835,72.818c0.656,1.521-0.043,3.287-1.563,3.945s-3.286-0.043-3.944-1.563c-2.894-6.688-9.729-11.013-17.42-11.013
                c-7.869,0-14.748,4.32-17.523,11.006c-0.48,1.152-1.596,1.85-2.771,1.852c-0.385,0-0.773-0.074-1.15-0.23
                c-1.531-0.637-2.256-2.393-1.619-3.922c3.709-8.933,12.764-14.703,23.064-14.703C62.993,58.189,71.993,63.932,75.835,72.818z
                 M28.452,36.484c-0.676-1.176-0.27-2.676,0.906-3.351l9.045-5.196c1.176-0.674,2.676-0.268,3.352,0.907
                c0.676,1.176,0.27,2.676-0.906,3.351l-9.045,5.194C30.626,38.065,29.126,37.66,28.452,36.484z M42.487,36.59
                c1.688,1.689,1.688,4.429,0,6.115c-1.688,1.688-4.426,1.688-6.117-0.002c-1.688-1.688-1.688-4.426,0-6.113
                C38.059,34.901,40.797,34.901,42.487,36.59z M57.188,21.907c0.121-1.35,1.312-2.347,2.662-2.226l10.391,0.934
                c1.35,0.121,2.348,1.313,2.225,2.664c-0.121,1.351-1.312,2.347-2.664,2.225l-10.389-0.933
                C58.063,24.45,57.065,23.256,57.188,21.907z M68.28,36.519c1.688,1.688,1.688,4.426,0,6.113c-1.691,1.69-4.43,1.69-6.117,0.002
                c-1.688-1.687-1.688-4.426,0-6.115C63.852,34.829,66.59,34.829,68.28,36.519z M85.465,103.695H18.23
                C8.178,103.695,0,95.518,0,85.465V18.23C0,8.177,8.179,0,18.23,0h67.235c10.053,0,18.229,8.178,18.229,18.23v67.235
                C103.696,95.518,95.518,103.695,85.465,103.695z M18.23,8.577c-5.322,0-9.652,4.33-9.652,9.652v67.234
                c0,5.322,4.33,9.652,9.652,9.652h67.235c5.321,0,9.651-4.33,9.651-9.652V18.23c0-5.322-4.33-9.652-9.651-9.652L18.23,8.577
                L18.23,8.577z" />
      </svg>

      <svg id="icon-ok" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 .........完整代码请登录后点击上方下载按钮下载查看

网友评论0