发表于: 2020-08-01 23:04:19

1 1268


今天完成的事情:

绑定input滑动条


css:

            .box {
                displayflex;
                justify-contentspace-around;
                align-itemscenter;
                width50%;
                margin.2rem auto 0 auto;
            }

            /*横条样式*/
            input[type=range] {
                -webkit-appearancenone;
                /*清除系统默认样式*/
                width90%;
                height5px;
                /*横条的高度*/
                background-color#fab344;
                outlinenone;
                cursorpointer;
            }

            /*拖动块的样式*/
            input[type=range]::-webkit-slider-thumb {
                -webkit-appearancenone;
                /*清除系统默认样式*/
                width3.7rem;
                height2.2rem;
                backgroundurl("./images/设置页面_01.png"no-repeat;
                bordernone;
                cursorpointer;
            }

            .pic1 {
                width2.2rem;
                height2.2rem;
                backgroundurl("./images/设置页面_02.png"no-repeat 50%;
                outlinenone;
                bordernone;
            }

            .pic2 {
                width2.2rem;
                height2.2rem;
                backgroundurl("./images/设置页面_03.png"no-repeat 50%;
                outlinenone;
                bordernone;
            }



js

        <div class="box">
            <input type="button" class="pic1" onclick="btLeft()">
            <input type="range" id="rangeNumber" oninput="change()" name="change" value="4" min="4" max="18" step="1">
            <input type="button" class="pic2" onclick="btRight()">
        </div>

        <script>
            var inputNumber = document.getElementById("inputNumber");
            var rangeNumber = document.getElementById("rangeNumber");
            //玩家人数的输入框与滚动条同步
            function getNumber() {
                if (inputNumber.value >= 4 && inputerNumber.value <= 18) {
                    inputNumber.value = rangeNumber.value;
                }
                else {
                    alert("请输入玩家人数");
                }
            }
            //滚动条改变玩家人数随着改变
            function change() {
                inputNumber.value = rangeNumber.value;
            }
            //减号按钮与滚动条同步
            function btLeft() {
                rangeNumber.value--;
                if (inputNumber.value <= 4) {
                    alert("人数不足");
                }
                else {
                    inputNumber.value = rangeNumber.value;
                }
            }
            //加号按钮与滚动条同步
            function btRight() {
                rangeNumber.value++;
                if (inputNumber.value >= 18) {
                    alert("人数太多");
                }
                else {
                    inputNumber.value = rangeNumber.value;
                }
            }




返回列表 返回列表
评论

    分享到