Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

javascript - Bootstrap slider How can I move the tooltip value to external one?

I'm using the Bootstrap slider plugin to create a Range Slider

in Example 2 I want to remove the tooltip option and move the value to external one.

Here my code :

HTML

<b class="min">$ 10</b> 
<input id="example2" type="text" data-slider-min="0" data-slider-max="2000" data-slider-step="1" data-slider-value="14" data-slider-tooltip="hide" /> 
<b class="max">$ 1000</b>

JavaScript

var slider = new Slider('#example2', {});
question from:https://stackoverflow.com/questions/65868947/bootstrap-slider-how-can-i-move-the-tooltip-value-to-external-one

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you can use slide event to get current value and embed the value where you want :

slider.on("slide", function(sliderValue) {
    //do stuff here
});

You can see here Snippet example :

$(function() {

  var slider = new Slider('#example2', {});

  slider.on("slide", function(sliderValue) {
    document.getElementById("value").textContent = sliderValue;
  });

})
#value {
  color:red;
  font-weight:bold;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/11.0.2/css/bootstrap-slider.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/11.0.2/bootstrap-slider.min.js"></script>

<b class="min">$ 10</b>
<input id="example2" type="text" data-slider-min="10" data-slider-max="1000" data-slider-step="1" data-slider-value="14" data-slider-tooltip="hide" />
<b class="max">$ 1000</b>

<br><br> value :
<div id="value"></div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...