使用 jQuery UI 滑块自定义范围/变量集 [英] Custom Range/Variable Set with jQuery UI Slider

查看:21
本文介绍了使用 jQuery UI 滑块自定义范围/变量集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看看是否可以制作一个自定义数据集以与 jQuery UI Slider 一起使用.我正在一个网站上工作,该网站的着装尺寸范围为:[0、2、4、6、8、10、12、14、16、18、16W、18W、20W]

I wanted to see if I could make a custom data set to use with jQuery UI Slider. I'm working on a site that has dress sizes that come in the range of: [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 16W, 18W, 20W ]

我遇到的问题是在 18 岁之后出现的,当它跳到有点独特的宽"尺寸时.

The issue I'm having arises right after 18, when it jumps to "wide" sizes that are a bit unique.

在添加 16W、18W 和尺寸之前,我使用以下代码创建了一个工作滑块:

Before I added in the 16W, 18W, and on sizes, I created a working slider using the following code:

$("#slider-size .slider").slider({
  min: 0,
  max: 18,
  step: 2,
  slide: function(event, ui) {
    $(".rsize").text(ui.value);
  }
});

该函数中的最后一个参数会在滑块更改时更改文本值.

有人知道如何将 16W、18W 等添加到此列表的末尾吗?

谢谢!

推荐答案

对于自定义尺寸,您可以为标签使用另一个数组:

for custom sizes, you may use another array for your labels:

var sizes = ["0","2","4","6","8","10","12","14","16","18","16W","18W","20W"];
$("#slider-size .slider").slider({
  min: 0,
  max: sizes.length - 1,
  step: 1,
  slide: function(event, ui) {
    $(".rsize").text(sizes[ui.value]);
  }
});

现在,要添加或删除尺寸,只需修改 sizes 数组.

Now, to add or remove sizes, just modify the sizes array.

这篇关于使用 jQuery UI 滑块自定义范围/变量集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆