触控渐进增强范围滑块 jQuery Quinn

  • 源码大小:183.2KB
  • 所需积分:1积分
  • 源码编号:19JP-3560
  • 浏览次数:905次
  • 最后更新:2023年06月26日
  • 所属栏目:表单
本站默认解压密码:19jp.com 或 19jp_com

简介

范围滑块是表示数量的好方法。它是一个图形控制元素,允许用户从连续范围中选择一个值。它是将一个连续值,如距离或大小,转换为一系列离散值,通常是数字。

它通常用作页面上的输入字段,用户需要从预定义的集合中选择一个或多个解决方案。它非常适合选择持续时间(例如轮班)、选择菜单中的食物、选择交通选项和其他具有预定义数量的东西。

Quinn是一个轻量级的jQuery插件,它提供了一种直接的方法来创建自定义的、支持触摸的渐进增强范围滑块,当JavaScript不可用时,该滑块会优雅地降级为标准范围输入。

滑块控件不仅允许单个值,还允许用户在两个/多个约束之间选择数值。

参见:

  • JavaScript中的10个最佳范围滑块插件

如何使用它:

1.在文档中加载Quinn插件和其他所需资源。

  1. <!-- Required -->
  2. <script src="/path/to/cdn/jquery.min.js"></script>
  3. <script src="/path/to/cdn/underscore-min.js"></script>
  4.  
  5. <!-- jQuery Quinn Plugin -->
  6. <link rel="stylesheet" href="quinn.css" />
  7. <script src="/path/to/jquery.quinn.min.js"></script>

2.初始化插件以生成基本范围滑块。

  1. <div class="slider"></div>
  1. $('.slider').quinn({
  2. // options here
  3. });

3.或者在现有范围输入上初始化插件。

  1. <input type="range" value="0" />
  1. $('input[type=range]').quinn({
  2. // options here
  3. });

4.使用改变回调。

  1. $('.slider').quinn({
  2. change: function (newValue, slider) {
  3. console.log(newValue);
  4. }
  5. });

5.将您自己的样式应用于滑块。

  1. .slider {
  2. height: 5px;
  3. }
  4.  
  5. .slider .bar .left, .slider .bar .main, .slider .bar .right,
  6. .slider .active-bar .left, .slider .active-bar .main,
  7. .slider .active-bar .right, .slider .handle {
  8. background-image: url(bg.png);
  9. }
  10.  
  11. .slider .bar, .slider .bar .left, .slider .bar .main,
  12. .slider .bar .right, .slider .active-bar .left,
  13. .slider .active-bar .main, .slider .active-bar .right {
  14. height: 25px;
  15. }
  16.  
  17. .slider .handle {
  18. height: 24px;
  19. width: 24px;
  20. }

6.可用于自定义范围滑块的选项。

  1. $('.slider').quinn({
  2.  
  3. // minimum value
  4. min: 0,
  5.  
  6. // maximum value
  7. max: 100,
  8.  
  9. // If you wish the slider to be drawn so that it is wider than the
  10. // range of values which a user may select, supply the values as a
  11. // two-element array.
  12. drawTo: null,
  13.  
  14. // step size
  15. step: 1,
  16.  
  17. // initial value
  18. value: null,
  19.  
  20. // Snaps the initial value to fit with the given "step" value. For
  21. // example, given a step of 0.1 and an initial value of 1.05, the
  22. // value will be changes to fit the step, and rounded to 1.1.
  23. //
  24. // Notes:
  25. //
  26. // * Even with `strict` disabled, initial values which are outside
  27. // the given `min` and `max` will still be changed to fit within
  28. // the permitted range.
  29. //
  30. // * The `strict` setting affects the *initial value only*.
  31. strict: true,
  32.  
  33. // Restrics the values which may be chosen to those listed in the
  34. // `only` array.
  35. only: null,
  36.  
  37. // Disables the slider when initialized so that a user may not change
  38. // it's value.
  39. disable: false,
  40.  
  41. // By default, Quinn fades the opacity of the slider to 50% when
  42. // disabled, however this may not work perfectly with older Internet
  43. // Explorer versions when using transparent PNGs. Setting this to 1.0
  44. // will tell Quinn not to fade the slider when disabled.
  45. disabledOpacity: 0.5,
  46.  
  47. // If using Quinn on an element which isn't attached to the DOM, the
  48. // library won't be able to determine it's width; supply it as a
  49. // number (in pixels).
  50. width: null,
  51.  
  52. // If using Quinn on an element which isn't attached to the DOM, the
  53. // library won't be able to determine the width of the handle; suppl
  54. // it as a number (in pixels).
  55. handleWidth: null,
  56.  
  57. // Enables a slightly delay after keyboard events, in case the user
  58. // presses the key multiple times in quick succession. False disables,
  59. // otherwise provide a integer indicating how many milliseconds to
  60. // wait.
  61. keyFloodWait: false,
  62.  
  63. // When using animations (such as clicking on the bar), how long
  64. // should the duration be? Any jQuery effect duration value is
  65. // permitted.
  66. effectSpeed: 'fast',
  67.  
  68. // Set to false to disable all animation on the slider.
  69. effects: true,
  70.  
  71. });

7.回调和函数。

  1. $('.slider').quinn({
  2.  
  3. // A callback which is run when changing the slider value. Additional
  4. // callbacks may be added with Quinn::on('drag').
  5. //
  6. // Arguments:
  7. // number: the altered slider value
  8. // Quinn: the Quinn instance
  9. //
  10. drag: null,
  11.  
  12. // Run after the user has finished making a change.
  13. //
  14. // Arguments:
  15. // number: the new slider value
  16. // Quinn: the Quinn instance
  17. //
  18. change: null,
  19.  
  20. // Run once after the slider has been constructed.
  21. //
  22. // Arguments:
  23. // number: the current slider value
  24. // Quinn: the Quinn instance
  25. //
  26. setup: null,
  27.  
  28. // An optional class which is used to render the Quinn DOM elements
  29. // and redraw them when the slider value is changed. This should be
  30. // the class; Quinn will create the instance, passing the wrapper
  31. // element and the options used when $(...).quinn() is called.
  32. //
  33. // Arguments:
  34. // Quinn: the Quinn instance
  35. // object: the options passed to $.fn.quinn
  36. //
  37. renderer: Quinn.Renderer,
  38.  
  39. });

更新日志:

v1.2.2 (2022-05-24)

  • 修复默认CSS中的句柄位置。

预览截图