vue js css 刻度尺选取体重身高


css

复制代码
rem=  document.documentElement.clientWidth / 7.5 + "px";

 .weightAndHeight {
                width: 6.54rem;
                box-sizing: border-box;
                margin: 0 auto;
                background-color: #fff;
                border-radius: 12px;
                padding: 0.32rem;
                .title {
                    font-size: 0.32rem;
                    color: #222;
                    line-height: 0.5rem;
                    margin-bottom: 0.2rem;
                }
                .box {
                    &:first-child {
                        margin-bottom: 1.5rem;
                    }
                    &:last-child {
                        margin-bottom: 1rem;
                    }
                    position: relative;
                }
                //刻度尺
                .rulerContainer {
                    position: relative;
                    //红色刻度线
                    &::after {
                        content: "";
                        position: absolute;
                        // width: 20px;
                        height: 0.32rem;
                        border-right: 2px solid #FF4E3E;
                        top: 0.74rem;
                        left: calc(50% - 1px);
                    }
                    .scaleBox {
                        overflow-x: scroll;
                        //去除滚动条
                        &::-webkit-scrollbar {
                            display: none;
                        }
                        height: 65px;
                  		.ruler {
                            margin: 0 2.95rem;
                            display: inline-block;
                            width: 960px;
                            //刻度图片见文章上面
                            background-image: url(../img/testInfo/scale.png);
                            height: 16px;
                            background-repeat: repeat;
                            background-size: contain;
                            ul {
                                display: flex;
                                align-items: center;
                                justify-content: space-between;
                                position: relative;
                                top: -25px;
                                left: -5px;
                                li {
                                    list-style: none;
                                    font-size: 12px;
                                    color: #999;
                                    width: 60px;
                                }
                            }
                        }
                    }
                    //左右阴影部分
                    .shadowLeft {
                        position: absolute;
                        left: 0;
                        width: 0.6rem;
                        height: 1.1rem;
                        background-size: cover;
                        background-image: url(../img/testInfo/left.png);
                    }
                    .shadowRight {
                        position: absolute;
                        right: 0;
                        width: 0.6rem;
                        height: 1.1rem;
                        background-size: cover;
                        background-image: url(../img/testInfo/right.png);
                    }
                }
                //刻度值显示
                .data {
                    margin-top: 0.2rem;
                    position: absolute;
                    width: 100%;
                    text-align: center;
                    font-size: 0.48rem;
                    color: #1f1f1f;
                    font-weight: bold;
                    span {
                        font-size: 0.28rem;
                        color: #1f1f1f;
                    }
                }
                .rulerContainer2 {
                    @extend .rulerContainer;
                    .scaleBox {
                        .ruler {
                            width: 1320px;
                        }
                    }
                }
            }

**

html

**

复制代码
<div class="weightAndHeight">
                <div class="box">
                    <div class="title">体重</div>
                    <div class="rulerContainer">
                        <div class="shadowLeft"></div>
                        <div class="shadowRight"></div>
                        <div class="scaleBox weightScaleBox" @scroll="handleScroll('weight')" @touchEnd="handleScrollEnd('weight')">
                            <div class="ruler">
                                <ul>
                                    <li>0</li>
                                    <li>10</li>
                                    <li>20</li>
                                    <li>30</li>
                                    <li>40</li>
                                    <li>50</li>
                                    <li>60</li>
                                    <li>70</li>
                                    <li>80</li>
                                    <li>90</li>
                                    <li>100</li>
                                    <li>110</li>
                                    <li>120</li>
                                    <li>130</li>
                                    <li>140</li>
                                    <li>150</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="data">{{form.weight}}<span>kg</span></div>
                </div>
                <div class="box">
                    <div class="title">身高</div>
                    <div class="rulerContainer2">
                        <div class="shadowLeft"></div>
                        <div class="shadowRight"></div>
                        <div class="scaleBox heightScaleBox" @scroll="handleScroll" @touchEnd="handleScrollEnd">
                            <div class="ruler">
                                <ul>
                                    <li>30</li>
                                    <li>40</li>
                                    <li>50</li>
                                    <li>60</li>
                                    <li>70</li>
                                    <li>80</li>
                                    <li>90</li>
                                    <li>100</li>
                                    <li>110</li>
                                    <li>120</li>
                                    <li>130</li>
                                    <li>140</li>
                                    <li>150</li>
                                    <li>160</li>
                                    <li>170</li>
                                    <li>180</li>
                                    <li>190</li>
                                    <li>200</li>
                                    <li>210</li>
                                    <li>220</li>
                                    <li>230</li>
                                    <li>240</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="data">{{form.height}}<span>cm</span></div>
                </div>

            </div>

**

js

**

复制代码
data() {
            return {
                type: 1,
                form: {
                	weight: 65,
                    height: 175
                },
                nearWeightNumber: "",
                nearHeightNumber: "",
            };
        }

页面初始化的时候

复制代码
this.nearWeightNumber = this.form.weight * 6;
this.nearHeightNumber = (this.form.height - 30) * 6;//我身高最小值是30所以-30
document.getElementsByClassName("weightScaleBox")[0].scrollLeft = this.nearWeightNumber;
document.getElementsByClassName("heightScaleBox")[0].scrollLeft = this.nearHeightNumber;

滚动条滚动的时候调用

复制代码
handleScroll(type) {
                if (type == "weight") {
                    let scrollLeft = document.getElementsByClassName("weightScaleBox")[0].scrollLeft;
                    let number = (scrollLeft / 60).toFixed(1);//我单个刻度条的宽度是60
                    this.nearWeightNumber = number * 60//就近的刻度线的像素
                    this.form.weight = number * 10;
                } else {
                    let scrollLeft = document.getElementsByClassName("heightScaleBox")[0].scrollLeft;
                    let number = (scrollLeft / 60).toFixed(1);
                    this.nearHeightNumber = number * 60
                    this.form.height = number * 10 + 30;
                }
            },
            //滚动结束时 需要滚动到就近的刻度线的像素 也就是滚动时候存下来的变量
            handleScrollEnd(type) {
                if (type == "weight") {
                    document.getElementsByClassName("weightScaleBox")[0].scrollLeft = this.nearWeightNumber;
                } else {
                    document.getElementsByClassName("heightScaleBox")[0].scrollLeft = this.nearHeightNumber;
                }
            }
相关推荐
deli00733 分钟前
Redis 缓存穿透、击穿、雪崩:9 组流量实测数据库怎么被打穿
前端
江华森38 分钟前
5Mbps 小水管也能扛:K3s 上 k6 压测 + HPA 弹性伸缩实测
前端
shuangyueliao1 小时前
103 个小游戏的商店素材,我一张图都没手动做:截图 / 封面 / 打包 / 提审全自动
前端
用户2763965765101 小时前
放弃 JWT 后,我给 FastAPI 游戏服务端手撸了一套 token session
javascript
ZhengEnCi1 小时前
前端项目为什么需要一份统一的 theme.css:用 CSS 变量管住全局样式与主题切换
前端·css·前端工程化
wordbaby1 小时前
一次微信小程序 `web-view` 跳转原生页回跳后 H5 白屏的排查与修复(Hash 路由污染)
前端
用户721880438351 小时前
密码骰子:结合AIUI在眼镜上生成一串16位密码
前端
江华森1 小时前
全链路可观测落地记:kube-prometheus-stack 在 K3s 上的 8 个坑与一整套修复脚本
前端
用户84298142418101 小时前
从 JavaScript 到可运行的字节码 - ByteJS 使用指南
javascript
deli0072 小时前
27 寸 4K 开 125% 为什么发虚?PPI 和缩放一次算清
前端