css+js实现带刻度滑动拖动数字选择效果代码

代码语言:html

所属分类:选择器

代码描述:css+js实现带刻度滑动拖动数字选择效果代码

代码标签: css js 刻度 滑动 拖动 数字 选择

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

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background: #222237;
            display: flex;
            justify-content: center;
            min-height: 100vh;
            user-select: none;
            -webkit-font-smoothing: antialiased;
            font-family: "Microsoft YaHei UI", \82f9\65b9, Helvetica, Arial Light;
            overflow: hidden;
        }

        h1 {
            margin: 1.5em 0 0.5em;
            color: #eee;
            font-size: 1.5em;
            padding: 0.625em;
            font-weight: normal;
        }

        ul {
            width: 100vw;
            min-width: 100px;
        }

        ul li {
            list-style: none;
            font-size: 2.75em;
            height: 60px;
            text-align: center;
            cursor: inherit;
        }

        section {
            width: 100vw;
            display: flex;
            align-items: center;
            flex-direction: column;
        }

        section h1 {
            width: 100%;
            color: #CC3300;
            text-align: center;
        }

        .container {
            position: relative;
            height: 18.75em;
            width: 90vw;
            max-width: 400px;
            display: flex;
            justify-content: center;
            overflow: hidden;
            cursor: grab;
            border-radius: 0.5em;
            box-shadow: 0 0 50px 0 #00000038;
            -webkit-mask: linear-gradient(0deg, transparent, #000, transparent);
            box-shadow: inset 0 0 50px 0 #00000038;
        }

        .container.grabbing {
            cursor: grabbing;
        }

        .time-picker {
            width: 100%;
            display: flex;
            flex-direction: row;
            transform: translateY( calc( var(--top) * 1px) );
        }

        .time-picker ul li {
            color: #CC6666;
            width: 100%;
            text-align: center;
        }

        .clip {
            position: absolute;
            display: flex;
            top: 120px;
            height: 60px;
            overflow: hidden;
        }

        .clip::before {
            content: '';
            position: absolute;
            left: calc( 50% - 5em );
            top: calc( 50% - 0.5em );
            width: 0;
            height: 0;
            border-left: 1em solid #CC3300;
            border-right: 0;
            border-top: 0.5em solid transparent;
            border-bottom: 0.5em solid transparent;
        }
        .clip::after {
            content: '';
            position: absolute;
            right: calc( 50% - 5em );
            top: calc( 50% - 0.5em );
            width: 0;
            height: 0;
            border-left: 0;
            border-right: 1em solid #CC3300;
            border-top: 0.5em solid transparent;
            border-bottom: 0.5em solid transparent;
        }

        .clip .wrapper {
            --num: 0;
            margin-top: -120px;
            transform: translateY( calc( var(--num) * -60px ) );
        }

        .clip ul li {
            color: #CC3300;
        }

        .transition-half-sec {
            transition:transform .3s;
        }


        .tip {
            margin-top: 2em;
            color: #417096;
            font-size: 1em;
            text-align: center;
            line-height: 1.5;
        }

    </style>
</head>
<body>
    <section>
        <h1>滑动数字选择控件</h1>
        <div class="container">
            <div class="time-picker" style="--top: 0">
                <ul>
                    <li>00</li>
                    <li>01</li>
                    <li>02</li>
                    <li>03</li>
                    <li>04</li>
                    <li>05</li>
                    <li>06</li>
                    <li>07</li>
                    <li>08</li>
                    <li>09</li>
                    <li>10</li>
                    <li>11</li>
                    <li>12</li>
                    <li>13</li>
                    <li>14</li>
                    <li>15</li>
                    <li>16</li>
                    <li>17</li>
                    <li>18</li>
                    <li>19</li>
                    <li>20</li>
                    <li>21</li>
                    <li>22</li>
                    <li>23</li>
                </ul>
            </div>
            <div class="clip">
                <div class="wrapper">
                    <ul>
                        <li>00</li>
                        <li>01</li>
                        <li>02</li>
                        <li>03</li>
                        <li>04</li>
                   .........完整代码请登录后点击上方下载按钮下载查看

网友评论0