<tfoot id='DLKTe'></tfoot>
  • <legend id='DLKTe'><style id='DLKTe'><dir id='DLKTe'><q id='DLKTe'></q></dir></style></legend>

    <i id='DLKTe'><tr id='DLKTe'><dt id='DLKTe'><q id='DLKTe'><span id='DLKTe'><b id='DLKTe'><form id='DLKTe'><ins id='DLKTe'></ins><ul id='DLKTe'></ul><sub id='DLKTe'></sub></form><legend id='DLKTe'></legend><bdo id='DLKTe'><pre id='DLKTe'><center id='DLKTe'></center></pre></bdo></b><th id='DLKTe'></th></span></q></dt></tr></i><div id='DLKTe'><tfoot id='DLKTe'></tfoot><dl id='DLKTe'><fieldset id='DLKTe'></fieldset></dl></div>
        <bdo id='DLKTe'></bdo><ul id='DLKTe'></ul>

      <small id='DLKTe'></small><noframes id='DLKTe'>

        在拇指顶部显示滑块范围值

        Show slider range value on top of thumb(在拇指顶部显示滑块范围值)
        <legend id='Bvuam'><style id='Bvuam'><dir id='Bvuam'><q id='Bvuam'></q></dir></style></legend>

            <tbody id='Bvuam'></tbody>

            <i id='Bvuam'><tr id='Bvuam'><dt id='Bvuam'><q id='Bvuam'><span id='Bvuam'><b id='Bvuam'><form id='Bvuam'><ins id='Bvuam'></ins><ul id='Bvuam'></ul><sub id='Bvuam'></sub></form><legend id='Bvuam'></legend><bdo id='Bvuam'><pre id='Bvuam'><center id='Bvuam'></center></pre></bdo></b><th id='Bvuam'></th></span></q></dt></tr></i><div id='Bvuam'><tfoot id='Bvuam'></tfoot><dl id='Bvuam'><fieldset id='Bvuam'></fieldset></dl></div>
            <tfoot id='Bvuam'></tfoot>

                • <bdo id='Bvuam'></bdo><ul id='Bvuam'></ul>

                  <small id='Bvuam'></small><noframes id='Bvuam'>

                  本文介绍了在拇指顶部显示滑块范围值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这个范围滑块,基于 W3Schools 提供的滑块.一切正常,除了我希望它的值显示在拇指上方,所以当你滑动它时,它会随之滑动.我在 JS 上尝试过一些东西,但它不起作用:这是我的代码:

                  I have this range slider, based on the one provided by W3Schools. Everything works fine, except that I want the value of it to show above the thumb, so when you slide it, it slides with it. I have tried something on JS, but it doesn't work: Here's my code:

                  HTML

                  <div class="simulador">
                      <div class="contenedor">
                          <h1 class="simula">Simular</h1>
                          <div class="slider-container">
                              <div class="interno">
                                  <div class="slidecontainer">
                                      <input type="range" min="5000" max="100000" value="50000" class="slider" id="rango" oninput="outputUpdate(val)">
                                      <output for="rango" id="valor"></output>
                                  </div>
                              </div>
                          </div>
                      </div>
                  </div>
                  

                  CSS(我使用的是 Sass,但这里是渲染)

                  CSS (I'm using Sass, but here's the render)

                  .simulador .contenedor {
                    padding: 25px 22px;
                  }
                  .simulador .contenedor .slider-container {
                    padding: 35px 0px;
                  }
                  .simulador .contenedor .slider-container .interno {
                    padding: 20px 0px;
                  }
                  .simulador .contenedor .slider-container .interno .slidecontainer {
                    width: 100%;
                    padding-top: 18px;
                  }
                  .simulador .contenedor .slider-container .interno .slidecontainer output {
                    font-family: 'museo700';
                    margin-bottom: 0px;
                    position: absolute;
                    padding: .5em;
                    background: transparent;
                    color: yellow;
                  }
                  .simulador .contenedor .slider-container .interno .slider {
                    -webkit-appearance: none;
                    width: 100%;
                    height: 5px;
                    border-radius: 2.5px;
                    background: #003664;
                    outline: none;
                    -webkit-transition: .2s;
                    transition: opacity .2s;
                    border: 0;
                  }
                  .simulador .contenedor .slider-container .interno .slider:hover {
                    opacity: 1;
                  }
                  .simulador .contenedor .slider-container .interno .slider::-webkit-slider-thumb {
                    -webkit-appearance: none;
                    appearance: none;
                    width: 22px;
                    height: 22px;
                    border-radius: 50%;
                    background: #fff;
                    cursor: pointer;
                    border: 3.5px solid yellow;
                  }
                  .simulador .contenedor .slider-container .interno .slider ::-moz-range-thumb {
                    width: 25px;
                    height: 25px;
                    border-radius: 50%;
                    background: #fff;
                    cursor: pointer;
                    border: 3.5px solid yellow;
                  }
                  

                  JavaScript

                  var slider = document.getElementById("rango");
                  var output = document.getElementById("valor");
                  output.innerHTML = slider.value;
                  
                  slider.oninput = function() {
                      output.innerHTML = this.value;
                  }
                  
                  function outputUpdate(val) {
                      var result = document.querySelector("#valor");
                      result.value = val;
                      result.style.left = val + 'px';
                  }
                  

                  推荐答案

                  这是给你的一个想法.只需将输出的 left 样式属性设置为大致等于圆的位置.这是通过将滑块宽度乘以滑块值与滑块范围的比率来完成的.

                  Here's an idea for you. Just setting the left style attribute of the output to roughly equal the position of the circle. This is done my multiplying the slider width by the ratio of the slider value to the slider range.

                  var slider = document.getElementById('rango');
                  
                  slider.oninput = function() {
                      var output = document.getElementById('valor');
                      output.innerHTML = this.value;
                      var sliderWidth = this.getBoundingClientRect().width;
                      var outputWidth = output.getBoundingClientRect().width;
                      var offset = this.value / (this.max - this.min) * sliderWidth - outputWidth / 2;
                      output.setAttribute('style', 'left: ' + offset + 'px');
                  }
                  
                  slider.oninput();

                  .simulador .contenedor {
                    padding: 25px 22px;
                  }
                  .simulador .contenedor .slider-container {
                    padding: 35px 0px;
                  }
                  .simulador .contenedor .slider-container .interno {
                    padding: 20px 0px;
                  }
                  .simulador .contenedor .slider-container .interno .slidecontainer {
                    width: 100%;
                    padding-top: 18px;
                  }
                  .simulador .contenedor .slider-container .interno .slidecontainer output {
                    font-family: 'museo700';
                    margin-bottom: 0px;
                    position: absolute;
                    padding: .5em;
                    background: transparent;
                    color: blue;
                  }
                  .simulador .contenedor .slider-container .interno .slider {
                    -webkit-appearance: none;
                    width: 100%;
                    height: 5px;
                    border-radius: 2.5px;
                    background: #003664;
                    outline: none;
                    -webkit-transition: .2s;
                    transition: opacity .2s;
                    border: 0;
                  }
                  .simulador .contenedor .slider-container .interno .slider:hover {
                    opacity: 1;
                  }
                  .simulador .contenedor .slider-container .interno .slider::-webkit-slider-thumb {
                    -webkit-appearance: none;
                    appearance: none;
                    width: 22px;
                    height: 22px;
                    border-radius: 50%;
                    background: #fff;
                    cursor: pointer;
                    border: 3.5px solid blue;
                  }
                  .simulador .contenedor .slider-container .interno .slider ::-moz-range-thumb {
                    width: 25px;
                    height: 25px;
                    border-radius: 50%;
                    background: #fff;
                    cursor: pointer;
                    border: 3.5px solid blue;
                  }

                  <div class="simulador">
                      <div class="contenedor">
                          <h1 class="simula">Simular</h1>
                          <div class="slider-container">
                              <div class="interno">
                                  <div class="slidecontainer">
                                      <input type="range" min="5000" max="100000" value="50000" class="slider" id="rango" oninput="outputUpdate(val)">
                                      <output for="rango" id="valor"></output>
                                  </div>
                              </div>
                          </div>
                      </div>
                  </div>

                  这篇关于在拇指顶部显示滑块范围值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                  How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?(如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?) - IT屋-程序员软件开发技术分享社
                  <tfoot id='gzB3V'></tfoot>
                      • <i id='gzB3V'><tr id='gzB3V'><dt id='gzB3V'><q id='gzB3V'><span id='gzB3V'><b id='gzB3V'><form id='gzB3V'><ins id='gzB3V'></ins><ul id='gzB3V'></ul><sub id='gzB3V'></sub></form><legend id='gzB3V'></legend><bdo id='gzB3V'><pre id='gzB3V'><center id='gzB3V'></center></pre></bdo></b><th id='gzB3V'></th></span></q></dt></tr></i><div id='gzB3V'><tfoot id='gzB3V'></tfoot><dl id='gzB3V'><fieldset id='gzB3V'></fieldset></dl></div>
                      • <legend id='gzB3V'><style id='gzB3V'><dir id='gzB3V'><q id='gzB3V'></q></dir></style></legend>

                          <small id='gzB3V'></small><noframes id='gzB3V'>

                            <tbody id='gzB3V'></tbody>
                            <bdo id='gzB3V'></bdo><ul id='gzB3V'></ul>