Js mobile phone number selection, sliding up and down too fast, how to slow down and roll a number?

the number on this phone scrolls too fast, how can you slow down and slide a number?

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .babygroup-picker{
            width: 420px
        }
        .babygroup-picker>input {
    float: left;
    width: 200px;
    height: 50px;
    font-size: 24px;
    text-align: center;
    border: 1px solid -sharpdcdddd;
    box-sizing: border-box;
    -webkit-appearance: none;
    border-radius: 0
}
.babygroup-pickoff {
    float: right;
    height: 50px;
}
.babygroup-pickoff ul{
    float: left;
    margin: 0;
    padding: 0;
}

.babygroup-pickoff li {
    float: left;
    width: 50px;
    height: 50px;
    font-size: 24px;
    color: -sharp595757;
    text-align: center;
    line-height: 50px;
    margin-left: 20px;
    border: 1px solid -sharpdcdddd;
    background: linear-gradient(to bottom, -sharpd7d8d8 0%, -sharpf4f4f4 50%, -sharpd7d8d8 100%);
    box-sizing: border-box;
    overflow: hidden
}
    </style>
</head>

<body>
    <div class="babygroup-picker">
        <input id="inline" type="text">
        <div class="babygroup-pickoff">
            <ul>
                <li>0</li>
                <li>0</li>
                <li>0</li>
            </ul>
        </div>
    </div>
    <script>
        // 
        var num = 0;
        $("body").on("touchstart", ".babygroup-pickoff li", function (e) {
            e.preventDefault();
            startX = e.originalEvent.changedTouches[0].pageX,
                startY = e.originalEvent.changedTouches[0].pageY;
        });
        $("body").on("touchmove", ".babygroup-pickoff li", function (e) {
            e.preventDefault();
            moveEndX = e.originalEvent.changedTouches[0].pageX,
                moveEndY = e.originalEvent.changedTouches[0].pageY,
                X = moveEndX - startX,
                Y = moveEndY - startY;
            if (Math.abs(Y) > Math.abs(X) && Y > 0) {
                num--;
                if (num < 0) {
                    num = 9;
                }
                $(this).html(num);
            } else if (Math.abs(Y) > Math.abs(X) && Y < 0) {
                numPP;
                if (num > 9) {
                    num = 0;
                }
                $(this).html(num);
            };
            $(".babygroup-picker input").val($(".babygroup-picker li").eq(0).html() + $(
                ".babygroup-picker li ").eq(1).html() + $(".babygroup-picker li").eq(2).html());
        });
    </script>
</body>

</html>
May.31,2022

introduces lodash , a very useful front-end tool class library

$("body").on("touchmove", '.babygroup-pickoff li', _.throttle(function(e) {
    //code...
}, 800))

you can learn more about front-end river closure and anti-shake https://codeshelper.com/a/11...


it should be slow to write a throttle


can be achieved by using lodash's debounce function, which can only trigger the first click within 1 second if you click multiple times.

do not use _ .throttle. This function will still be executed many times, but the next execution will be delayed.
look at lodash documents carefully

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38bf6-2c146.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38bf6-2c146.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?