Jul*_*ius 9 javascript integer tooltip nouislider
我希望我的滑块上的工具提示只显示"130"而不是"130.00"这样的整数.我只是不知道我可以从哪里开始.
这是我的代码:
$( document ).ready(function() {
var groesseslider = document.getElementById('slider-tooltip');
noUiSlider.create(groesseslider, {
start: [ 145 ],
step: 1,
range: {
'min': 100,
'max': 250
}
});
});
$( document ).ready(function() {
var groesseslider = document.getElementById('slider-tooltip');
var tipHandles = groesseslider.getElementsByClassName('noUi-handle'),
tooltips = [];
// Add divs to the slider handles.
for ( var i = 0; i < tipHandles.length; i++ ){
tooltips[i] = document.createElement('div');
tipHandles[i].appendChild(tooltips[i]);
}
// When the slider changes, write the value to the tooltips.
groesseslider.noUiSlider.on('update', function( values, handle ){
tooltips[handle].innerHTML = values[handle];
});
});
Run Code Online (Sandbox Code Playgroud)
我的JS代码:http: //jsfiddle.net/miiauwz/66a5ahm0/
小智 19
这可以工作..
var sliderFormat = document.getElementById('slider-format');
noUiSlider.create(sliderFormat, {
start: [ 20 ],
...
format: {
from: function(value) {
return parseInt(value);
},
to: function(value) {
return parseInt(value);
}
}
});
Run Code Online (Sandbox Code Playgroud)
SaS*_*chu 15
您可以尝试使用unencodednoUISlider关于事件及其绑定的文档中描述的值
slider.noUiSlider.on("update", function(values, handle, unencoded ) {
// values: Current slider values;
// handle: Handle that caused the event;
// unencoded: Slider values without formatting;
});
Run Code Online (Sandbox Code Playgroud)
或者另一种可能性是在滑块创建时使用格式选项(但还没有尝试过):
noUiSlider.create(slider, {
start: [ 20000 ],
...
format: wNumb({
decimals: 0, // default is 2
thousand: '.', // thousand delimiter
postfix: ' (US $)', // gets appended after the number
})
});
Run Code Online (Sandbox Code Playgroud)
缺点是你必须从这里单独下载wNumb-Library:http://refreshless.com/wnumb/ .
没有wNumb的另一种方式
再看一下noUISlider中的例子后,我发现这种方式可以手动格式化(在页面底部):
var sliderFormat = document.getElementById('slider-format');
noUiSlider.create(sliderFormat, {
start: [ 20 ],
...
format: {
to: function ( value ) {
return value + ',-';
},
from: function ( value ) {
return value.replace(',-', '');
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12194 次 |
| 最近记录: |