发表于: 2020-08-07 23:59:18

1 1196


今天完成的事情:

大致完成了页面布局

解决图片大小问题


css

            * {
                margin0;
                padding0;
                list-stylenone;
            }

            html {
                font-size62.5%;
            }

            body {
                background-color#f0f0f0;
            }

            .nav {
                displayflex;
                justify-contentspace-between;
                align-itemscenter;
                height4rem;
                font-size1.7rem;
                colorwhite;
                background-color#29bde0;
                margin-bottom1rem;
                padding0 2%;
            }

            .nav img {
                zoom.5;
            }

            main {
                width96%;
                margin0 auto;
                /* 
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                align-items: center;
                 */
            }

            .firstbox {
                displayflex;
                justify-contentspace-between;
                background-colorwhite;
                height30rem;
            }

            .box1 {
                width20%;
                text-aligncenter;
                font-size1.7rem;
                border-right1px solid black;

            }

            .box2 {
                width80%;
                positionrelative;

            }

            .bs {
                margin0 2rem;

                displayflex;
                justify-contentspace-between;
            }

            .bo {
                width100%;
                colorblue;
                text-aligncenter;
                padding2rem 0;
                border-top1px solid black;
                positionabsolute;
                bottom0;
            }

            #killer,
            #person {
                width40px;
                background-color#e1e1e1;
                border0;
                font-size1.4rem;
            }

            .boxs {
                background-colorwhite;
                font-size1.4rem;
                margin0.5rem 0;
            }

            .bigbox {
                background-colorwhite;
                width100%;
            }

            .box3 {
                height4rem;
                displayflex;
                align-itemscenter;
                /* justify-content: center; */
                width100%;
                font-size1.4rem;
            }

            #player {
                width40px;
                background-color#e1e1e1;
                border0;
                font-size1.4rem;
            }

            /* 滑动条布局 */
            .box4 {
                displayflex;
                justify-contentspace-around;
                align-itemscenter;
                width80%;
                margin2rem auto 2rem auto;
                zoom.5;
            }

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

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

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

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

            /* 发牌按钮 */
            .fn {
                text-aligncenter;
                margin-top20px;
            }

            .fn button {
                width96%;
                height50px;
                font-size2rem;
                colorwhite;
                background-colororange;
                border0;
                outlinenone;
            }


js:

           //获取输入玩家input节点
            var player = document.getElementById("player");
            // 获取杀手input节点
            var killer = document.getElementById("killer");
            // 获取平民input节点
            var person = document.getElementById("person");


            // 利用oninput输入事件触发玩家input属性
            player.oninput = function () {
                var x = /\D/g;//定义正则,非数字规则
                this.value = this.value.replace(x"");// 符合正则规则替换为空值
                gain(this.value);// 获取当前对象输入的值
            }

            var arr = [];


            // 把获取的值赋给killer和person两个input
            function gain(value) {
                killer.value = Math.round(value - (value / 2 + value / 6 + value / 24.1));
                person.value = Math.round(value / 2 + value / 6 + value / 24.1);

                // 当玩家值小于4或大于18赋给killer和person值为空
                if (value < 0 || value > 18) {
                    killer.value = "";
                    person.value = "";
                } else {

                    // 当玩家值小于4或大于18把killer和person以组数形式输出
                    for (var i = 0i < killer.valuei++) {
                        arr.push("杀手");//输出杀手的数量push到数组
                    }
                    for (var i = 0i < person.valuei++) {
                        arr.push("平民");//输出平民的数量push到数组
                    }
                }
            }
            gain(player.value);//自运行

            var array = arr;//访问全局变量arr

            // // 点击button按钮判断条件
            function button() {

                // 获取输入玩家input的value的值
                var count = document.getElementById("player").value;

                // 判断条件符合弹出提示窗口,否则进入下一个页面
                if (count < 0 || count > 18) {
                    confirm("请输入正确的玩家数量。");
                } else {

                    // 洗牌算法
                    if (array) {
                        for (var i = array.length - 1i > 0i--) {
                            // 打乱数组的玩家
                            var j = Math.floor(Math.random() * (i + 1));
                            var temp = array[i];
                            array[i] = array[j];
                            array[j] = temp;
                        }

                        console.log(array);
                    }
                    // location.href = "check.html";//进入下一个页面
                }
                return false;//冒泡事件
            }
            console.log(array);

            // 键盘事件
            document.onkeydown = function (event) {
                var e = event || window.event || arguments.callee.caller.arguments[0];
                if (e && e.keyCode == 13) {
                    button();
                }
            };

            function myFunction() {
                document.getElementById("player").onclick();
            }


            // 
            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;
                }
            }



遇到的问题

1.文字如何竖直排列

2.如何设置点击发牌时input框的值改变,目前实现了键盘事件的改变,点击事件不成功

            // 链接发牌按钮
            function myFunction() {
                document.getElementById("player").onclick();
            }



返回列表 返回列表
评论

    分享到