简体   繁体   English

如何偏移范围滑块上的矩形拇指

[英]How to offset a rectangular thumb on a Range Slider

Problem:问题:


I have a custom range slider that I made in Vue.js and it has a rectangular thumb, however I have this issue where the thumb extends over the edges of the track. 我有一个在 Vue.js 中制作的自定义范围滑块,它有一个矩形拇指,但是我遇到了拇指延伸超过轨道边缘的问题。

Code:代码:


 <template> <div class="slidecontainer"> <input v-model="updateSlider" type="range" min="2.5" max="100" step="0.5" class="slider" id="slider" @change="slider(updateSlider)" /> <div :style="{ left: updateSlider + '%' }" id="selector"> <div class="selector-thumb"> <p style="width: 100%; text-align: center; font-size: 1.45rem"> &#60; R{{ ((updateSlider / 0.5) * 1000) .toString() .replace(/\\B(?=(\\d{3})+(?!\\d))/g, " ") }} &#62; </p> </div> </div> </div> </template> <script> import { mapActions } from "vuex"; export default { computed: { updateSlider: { get() { return this.$store.getters.slider; }, set(value) { this.$store.dispatch("slider", value); }, }, }, methods: { ...mapActions(["slider"]), }, }; </script> <style scoped> div > p { margin-bottom: 0px; color: #6dbfe6; } .slidecontainer { width: 100%; position: relative; display: flex; } .slider { -webkit-appearance: none; appearance: none; width: 90%; height: 25px; background: #d3d3d3; outline: none; opacity: 0.7; -webkit-transition: 0.2s; transition: opacity 0.2s; border-radius: 50px; margin: auto; } .slider { opacity: 1; } #slider { -webkit-appearance: none; } #slider::-webkit-slider-runnable-track { position: relative; } #slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 250px; height: 250px; cursor: pointer; z-index: 999; position: relative; opacity: 0; /* background: orange; */ } #selector { height: 95px; width: 100px; position: absolute; top: -50%; left: 50%; transform: translate(-50%, -50%); z-index: 2; } .selector-thumb { height: 40px; width: 100px; background: black; background-size: cover; background-position: center; position: absolute; bottom: 0; z-index: 1; } #slider::before { bottom: -1rem; content: "R89"; height: 5rem; width: 5rem; background: #827ab7; position: absolute; border-radius: 50px; z-index: 2; color: white; text-align: center; vertical-align: middle; line-height: 5rem; font-size: 1.45rem; left: 0px; } #slider::after { bottom: -1rem; content: "R195"; height: 5rem; width: 5rem; background: #827ab7; position: absolute; border-radius: 50px; z-index: 2; color: white; text-align: center; vertical-align: middle; line-height: 5rem; font-size: 1.45rem; right: 0; } .selector-thumb > p { color: white; text-align: center; top: 50%; left: 50%; position: absolute; transform: translate(-50%, -50%); } @media screen and (max-width: 767px) { #slider::-webkit-slider-thumb { width: 150px; height: 100px; } } </style>

分钟的扩展

扩展到最大

Possible Solution可能的解决方案


Finding a way to offset the thumb by calculating its position on the X axis of the page. 通过计算其在页面 X 轴上的位置,找到一种偏移拇指的方法。 or dynamically translateX depending on positon. 或根据位置动态 translateX。

any other solutions?还有其他解决方案吗?

JsFiddle提琴手

Solution解决方案


Is simpler than what I thought it to be, you have to make the parent container's width smaller and then increase the pixel width of the track to extend outside the parent container by making the track absolute. 比我想象的要简单,您必须使父容器的宽度更小,然后通过使轨道绝对化来增加轨道的像素宽度以扩展到父容器之外。

this way the thumb stays inbetween the width of the parent container slidecontainer这样拇指保持在父容器slidecontainer容器的宽度slidecontainer

yet the track of the range slider still extends outside the bounds.然而范围滑块的轨迹仍然延伸到边界之外。

 .slidecontainer { width: 66%; position: relative; display: flex; justify-content: center; height:4rem; } .slider { -webkit-appearance: none; appearance: none; width: 145%; height: 25px; background: #d3d3d3; outline: none; opacity: 0.7; -webkit-transition: 0.2s; transition: opacity 0.2s; border-radius: 50px; margin: auto; position: absolute; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM