Foundation slider
Foundation sliders allow users to select range values by dragging them:
Sliders can be created using <div class="range-slider" data-slider>
. Inside the <div>
, add two <span>
elements: <span class="range-slider-handle">
Create a rectangle Slider (blue background), <span class="range-slider-active-segment">
is the gray horizontal bar behind the slider, which is the slider dragging area.
Note: The slider requires JavaScript. So you need to initialize oundation JS:
Instance
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body> <div style="padding:20px;"> <h2>区间滑块</h2> <p> .range-slider-handle 类创建一个滑块实体(蓝色矩形),.range-slider-active-segment 在滑块后添加灰色横条:</p> <div class="range-slider" data-slider> <span class="range-slider-handle"></span> <span class="range-slider-active-segment"></span> </div> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run instance»
Click the "Run instance" button to view the online instance
Rounded Corners and Disabled Sliders
Use the .radius
and .round
classes to add rounded corner sliders. Use the .disabled
class to disable the slider:
Instance
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body> <div style="padding:20px;"> <h2>圆角 & 禁用滑块</h2> <p>使用 <code>.radius</code> 和 <code>.round</code> 类来添加圆角滑块。使用 <code>.disabled</code> 类来禁用滑块:</p> <span>默认:</span> <div class="range-slider" data-slider> <span class="range-slider-handle"></span> <span class="range-slider-active-segment"></span> </div> <span>圆角:</span> <div class="range-slider radius" data-slider> <span class="range-slider-handle"></span> <span class="range-slider-active-segment"></span> </div> <span>圆形:</span> <div class="range-slider round" data-slider> <span class="range-slider-handle"></span> <span class="range-slider-active-segment"></span> </div> <span>禁用:</span> <div class="range-slider disabled" data-slider> <span class="range-slider-handle"></span> <span class="range-slider-active-segment"></span> </div> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Running Instance»
Click the "Run Instance" button to view an online instance
Vertical Slider
Use the .vertical-range
class and data-options= "vertical: true;"
To create a vertical slider:
Example
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body> <div style="padding:20px;"> <h2>垂直滑块</h2> <p>使用 <code>.vertical-range</code> 类和 <code>data-options="vertical: true;"</code> 来创建垂直滑块:</p> <div class="range-slider vertical-range" data-slider data-options="vertical: true;"> <span class="range-slider-handle"></span> <span class="range-slider-active-segment"></span> </div> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run Example»
Click the "Run Instance" button to view the online instance
Slider value
By default, the slider is placed in the middle of the horizontal bar (the value is "50 "). The default value can be modified by adding the data-options="initial: num"
attribute:
Instance
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body> <div style="padding:20px;"> <h2>默认滑块值</h2> <p>默认情况下,滑块放在横条的中间 (数值为 "50")。可以通过添加 <code>data-options="initial: <em>num</em>"</code> 属性来修改默认值:</p> <div class="range-slider" data-slider data-options="initial: 80;"> <span class="range-slider-handle"></span> <span class="range-slider-active-segment"></span> </div> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance
Display the slider value
If we need to drag the slider To display the value in real time when moving, you can add the data-options="display_selector:
#id" attribute in <div>
and the element id value is the same as the slider The id of the block matches the following example:
Instance
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body> <div style="padding:20px;"> <h2>显示滑块值</h2> <p>如果我们需要在滑块拖动时实时显示值,可以通过在 <code> <div></code> 中添加 <code>data-options="display_selector:#<em>id</em>"</code> 属性且元素 id 值与滑块的 id 匹配,如下实例:</p> <span id="mySlider"></span> <div class="range-slider" data-slider data-options="display_selector: #mySlider;"> <span class="range-slider-handle"></span> <span class="range-slider-active-segment"></span> </div> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view Online Example
Combined Data Options
The following example uses the display_selector
and initial
data options:
Instance
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body> <div style="padding:20px;"> <h2>组合数据选项</h2> <p>以下实例使用了 <code>display_selector</code> 和 <code>initial</code> 数据选项:</p> <span id="mySlider"></span> <div class="range-slider" data-slider data-options="display_selector: #mySlider; initial:20;"> <span class="range-slider-handle"></span> <span class="range-slider-active-segment"></span> </div> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run instance»
Click the "Run instance" button to view the online instance
Step length
By default, the amount of increase or decrease when the slider slides is "1". The step value can be modified by adding the data-options="step: num;"
attribute. Set to 25 in the instance:
Instance
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body> <div style="padding:20px;"> <h2>步长</h2> <p>默认情况下,滑块滑动的增加减少的数量为 "1"。可以通过添加 <code>data-options="step: <em>num</em>;"</code> 属性来修改长值。实例中设置为 25:</p> <span id="mySlider"></span> <div class="range-slider" data-slider data-options="display_selector: #mySlider; step: 25;"> <span class="range-slider-handle"></span> <span class="range-slider-active-segment"></span> </div> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run instance»
Click the "Run instance" button to view the online instance
Custom interval
By default, the interval value is from "0" to "100". Interval values can be set by adding data-options start
and end
. The following example sets the interval value from "1" to "20":
Instance
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body> <div style="padding:20px;"> <h2>自定义区间</h2> <p>默认情况下,区间值在 "0" 到 "100"。可以通过添加 data-options <code>start</code> 和 <code>end</code> 来设置区间值。以下实例设置区间值为 "1" 到 "20":</p> <span id="mySlider"></span> <div class="range-slider" data-slider data-options="display_selector: #mySlider; start: 1; end: 20;"> <span class="range-slider-handle"></span> <span class="range-slider-active-segment"></span> </div> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run instance»
Click "Run instance" button to view the online instance
Using the grid
The following is used to use the slider in the grid:
Instance
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body> <div class="row"> <h2>使用网格</h2> <p>以下使用为在网格中使用滑块:</p> <div class="small-10 columns"> <div class="range-slider" data-slider data-options="display_selector: #mySlider;"> <span class="range-slider-handle"></span> <span class="range-slider-active-segment"></span> </div> </div> <div class="small-2 columns"> <span id="mySlider" style="display:block;margin-top:14px;"></span> </div> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance
Use Input
The following example Use <input>
instead of <span>
to display the slider value:
Example
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body> <div class="row"> <h2>使用 Input</h2> <p>以下实例使用 <code><input></code> 取代 <code><span></code> 来显示滑块的值:</p> <div class="small-10 columns"> <div class="range-slider" data-slider data-options="display_selector: #mySlider; initial: 72;"> <span class="range-slider-handle"></span> <span class="range-slider-active-segment"></span> </div> </div> <div class="small-2 columns"> <input type="number" id="mySlider" style="margin-top:7px;" value="72"> </div> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance