【问题标题】:HTML5 slider bar. How to use the 'noUiSlider'HTML5 滑块。如何使用“noUiSlider”
【发布时间】:2018-05-31 10:59:34
【问题描述】:

下午好,

我正在尝试实现“noUIslider”滑动条 (http://refreshless.com/nouislider/),即使在他们主页上的第一个示例中也遇到了困难。

我已经下载了各种 css 和 js 并将它们解压缩到一个文件夹中。然后我写了以下 html 页面,但看起来没有任何工作正常(空白 html 页面)。关于我错过了什么的任何线索?

非常感谢您的帮助,祝您周日愉快。

最好的祝愿, 洛朗

<!DOCTYPE html>
<html>
<head>
<link href="nouislider.min.css" rel="stylesheet">
<style>
#showcase {
    margin: 0 20px;
    text-align: center;
}
#range {
    height: 300px;
    margin: 0 auto 30px;
}
#value-span,
#value-input {
    width: 50%;
    float: left;
    display: block;
    text-align: center;
    margin: 0;
}
</style>

</head>
<body>
<script src="nouislider.min.js"></script>
<script>
var range = document.getElementById('range');

noUiSlider.create(range, {
    start: [ 20, 80 ], // Handle start position
    step: 10, // Slider moves in increments of '10'
    margin: 20, // Handles must be more than '20' apart
    connect: true, // Display a colored bar between the handles
    direction: 'rtl', // Put '0' at the bottom of the slider
    orientation: 'vertical', // Orient the slider vertically
    behaviour: 'tap-drag', // Move handle on tap, bar is draggable
    range: { // Slider can select '0' to '100'
        'min': 0,
        'max': 100
    },
    pips: { // Show a scale with the slider
        mode: 'steps',
        density: 2
    }
});

var valueInput = document.getElementById('value-input'),
    valueSpan = document.getElementById('value-span');

// When the slider value changes, update the input and span
range.noUiSlider.on('update', function( values, handle ) {
    if ( handle ) {
        valueInput.value = values[handle];
    } else {
        valueSpan.innerHTML = values[handle];
    }
});

// When the input changes, set the slider value
valueInput.addEventListener('change', function(){
    range.noUiSlider.set([null, this.value]);
});
</script>
</body>

</html>

【问题讨论】:

    标签: javascript jquery css html nouislider


    【解决方案1】:

    <!DOCTYPE html>
    <html>
    <head>
        <link href="//cdn.bootcss.com/noUiSlider/8.5.1/nouislider.min.css" rel="stylesheet">
        <script src="//cdn.bootcss.com/noUiSlider/8.5.1/nouislider.js"></script>
        <style>
            #showcase {
                margin: 0 20px;
                text-align: center;
            }
            #range {
                height: 300px;
                margin: 0 auto 30px;
            }
            #value-span,
            #value-input {
                width: 50%;
                float: left;
                display: block;
                text-align: center;
                margin: 0;
            }
        </style>
    </head>
    <body>
        <div id="range"></div>
    </body>
    <script>
        var range = document.getElementById('range');
    
        noUiSlider.create(range, {
            start: [ 20, 80 ], // Handle start position
            step: 10, // Slider moves in increments of '10'
            margin: 20, // Handles must be more than '20' apart
            connect: true, // Display a colored bar between the handles
            direction: 'rtl', // Put '0' at the bottom of the slider
            orientation: 'vertical', // Orient the slider vertically
            behaviour: 'tap-drag', // Move handle on tap, bar is draggable
            range: { // Slider can select '0' to '100'
                'min': 0,
                'max': 100
            },
            pips: { // Show a scale with the slider
                mode: 'steps',
                density: 2
            }
        });
    
        var valueInput = document.getElementById('value-input'),
                valueSpan = document.getElementById('value-span');
    
        // When the slider value changes, update the input and span
        range.noUiSlider.on('update', function( values, handle ) {
            if ( handle ) {
                valueInput.value = values[handle];
            } else {
                valueSpan.innerHTML = values[handle];
            }
        });
    
        // When the input changes, set the slider value
        valueInput.addEventListener('change', function(){
            range.noUiSlider.set([null, this.value]);
        });
    </script>
    </html>

    【讨论】:

    • 非常感谢,这正是我想要的。享受你的星期天
    【解决方案2】:

    您的代码运行良好,您需要在 body 标记中添加一个 div。

    <div id="range"></div>
    

    至少这就是我前进的动力:)

    【讨论】:

      【解决方案3】:

      将脚本标签放在底部

      在正文标签中插入“”

      【讨论】:

        【解决方案4】:

        尝试将您的自定义 js 包装在分配给 window.onload 事件的函数内的 &lt;script&gt; 标记中。

        <script>
          window.onload = function() {
            … // your custom code here
          }
        </script>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-12-26
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多