Home  >  Article  >  Web Front-end  >  jQuery+jRange实现滑动选取数值范围特效_jquery

jQuery+jRange实现滑动选取数值范围特效_jquery

WBOY
WBOYOriginal
2016-05-16 16:09:391789browse

有时我们在页面上需要选择数值范围,如购物时选取价格区间,购买主机时自主选取CPU,内存大小配置等,使用直观的滑块条直接选取想要的数值大小即可,无需手动输入数值,操作简单又方便。

HTML

首先载入jQuery库文件以及jRange相关的css文件:jquery.range.css和插件:jquery.range.js

复制代码 代码如下:




然后在需要展示滑块选择器的位置放入以下代码:

复制代码 代码如下:


我们使用了hiiden类型的文本域,设置默认值value,如23。

jQuery

调用jRange插件非常简单,直接用下面的代码:

复制代码 代码如下:

$('.single-slider').jRange({
    from: 0,
    to: 100,
    step: 1,
    scale: [0,25,50,75,100],
    format: '%s',
    width: 300,
    showLabels: true,
    showScale: true
});

然后运行你的网页,你将看到DEMO中的效果。

选项设置

插件jRange也提供了一些必要的选项设置来满足各种需求。

选项 说明 默认值
from 滑动范围的最小值,数字,如0  
to 滑动范围的最大值,数字,如100  
step 步长值,每次滑动大小 1
scale 滑动条下方的尺度标签,数组类型,如[0,50,100] [from,to]
showLabels 布尔型,是否显示滑动条下方的尺寸标签 true
showScale 布尔型,是否显示滑块上方的数值标签 true
format 数值格式 "%s"
width 滑动条宽度 300
isRange 是否为选取范围。 false

更多信息请参阅jRange项目官网:https://github.com/nitinhayaran/jRange

以上就是本文的全部内容了,有需要的小伙伴参考下,希望大家能够喜欢。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn