简体   繁体   English

如何更改 jQuery UI 范围滑块宽度

[英]How to change jQuery UI range slider width

I have two range sliders ( slider1, slider2).我有两个范围滑块(滑块 1、滑块 2)。 What I want: when the user starts sliding with mouse on the slider1 then the position( or width) and the value to be same on the slider2 as slider 1.我想要的是:当用户开始在滑块 1 上用鼠标滑动时,滑块 2 上的位置(或宽度)和值与滑块 1 相同。

My current code :我目前的代码:

<p>
        <label for="amount">Distance</label>
        <input type="text" id="amount">
    </p>
<!--Range slider-->  
  <div class='col-xl-6 col-lg-6 col-md-6 col-xs-12' id='slide'>

  </div>
  <p>
    <label for="amount2">Distance</label>
    <input type="text" id="amount2">
</p>
  <div class='col-xl-6 col-lg-6 col-md-6 col-xs-12' id='slide2'>

  </div>

    <script>
         $( function() {
        $( "#slide" ).slider({
          range: 'min',
          min: 0,
          max: 5000,
          value: 0,
         
    });
    $( function() {
        $( "#slide2" ).slider({
          range: 'min',
          min: 0,
          max: 5000,
          value: 0,
    
        })
    
    });
    </script>

I know that I have to use the slide event, but I cant change the position of the slide2, thanks in advance我知道我必须使用幻灯片事件,但我无法更改幻灯片 2 的位置,提前致谢

You can use slide event this will get called when user slide the slider then use slider("value") to get value and finally set value to both slider.您可以使用滑动事件,这将在用户滑动滑块时调用,然后使用slider("value")获取值并最终将值设置为两个滑块。

Demo Code :演示代码

 $(function() { $("#slide").slider({ range: 'min', min: 0, max: 5000, value: 0, }); $("#slide2").slider({ range: 'min', min: 0, max: 5000, value: 0 }); //on slide of slider call this $(".slides").on("slide", function() { var selection = $(this).slider("value"); //get value $(".slides").slider("value", selection); //set that value in both }); });
 <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <link rel="stylesheet" href="/resources/demos/style.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <p> <label for="amount">Distance</label> <input type="text" id="amount"> </p> <!-- Range slider 1 --> <div class="slides" id="slide"></div> <p> <label for="amount2">Distance</label> <input type="text" id="amount2"> </p> <!-- Range slider 2 --> <div class="slides" id="slide2"></div>

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

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