简体   繁体   English

基础范围滑块无法施加限制

[英]Foundation Range Slider Cannot Impose Limits

I currently have a screen that can have multiple range sliders on it. 我目前有一个屏幕,上面可以有多个范围滑块。 Each slider has a total range of 0 to the maximum the combination of sliders can have. 每个滑块的总范围为0到滑块组合可以具有的最大范围。 For example start: 0; end: 20; 例如start: 0; end: 20; start: 0; end: 20;

Within my application I would like to set some limits for the values a user can select via the sliders. 在我的应用程序中,我想为用户可以通过滑块选择的值设置一些限制。 So while the slider visual range gives you the full appearance of 0 - 20 for each individual slider the user can only select 2 - 10 and then I later validate that the total sum of all the sliders is within an acceptable range up to 20. 因此,尽管滑块的可视范围为每个单独的滑块提供了0-20的完整外观,但用户只能选择2-10,然后我稍后验证所有滑块的总和是否在可接受的范围内(最多20)。

currently I have some code like this which seems to do nothing 目前我有一些类似的代码,似乎什么也没做

self.$qtyForm.on('change.fndtn.slider', '.range-slider', function (e) {
    var $rng = $(this),
        qty = parseInt($rng.data('slider'), 10);

    if (qty > maxChoiceQty) {
        $rng.foundation('slider', 'set_value', maxChoiceQty);
    }

    if (qty < minChoiceQty) {
        $rng.foundation('slider', 'set_value', minChoiceQty);
    }
});

I also noticed that as soon as I touch the slider knob the change event fires. 我还注意到,只要触摸滑块旋钮,就会触发更改事件。 So this is actually firing like 50 times while the user is changing the range that doesn't seem right. 因此,在用户更改似乎不合适的范围时,实际上触发了50次。 any way to limit that or use another event 任何限制或使用其他事件的方式

jQuery stores data- attributes internally once loaded. jQuery加载后在内部存储数据属性。 Replace this line: 替换此行:

qty = parseInt($rng.data('slider'), 10)

with this: 有了这个:

qty = $($rng).attr('data-slider')

and you should get the current slider value. 您应该获得当前的滑块值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM