svg+js实现滑动条滑动打分评分动画效果代码

代码语言:html

所属分类:星级评分

代码描述:svg+js实现滑动条滑动打分评分动画效果代码

代码标签: 滑动 打分 评分 动画 效果

下面为部分代码预览,完整代码请点击下载或在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>Rate your experience</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.25.........完整代码请登录后点击上方下载按钮下载查看

网友评论0