jQuery 滑块问题达到最小值和最大值

发布于 2024-08-18 07:55:59 字数 241 浏览 7 评论 0原文

我初始化了一个 jQuery 滑块,然后根据 json 请求的内容动态设置最小最大值。步数甚至 100、最小和最大都会重新计算为甚至一百,大多数情况下在 300 到 4800 之间。

滑块值和设置都很好,但当我移动手柄时,我无法将其一直移动到结束时,它会从最小/最大值停止几步。这是为什么?

我已经尝试了各种方法,但没有任何作用。我最终在最高值处加上 200,并在较低值处减去 200 来进行补偿,但这是一种 hack,而不是解决方案。

I have a jQuery slider initialized and then dynamically set min max values depeding on the contents of a json-request. Steps av even 100, min a max are recalculated to even hundred, most of the case somewhere between 300 and 4800.

The slider values and settings are fine, but when I move the handle I can't get it all the way out to the ends, it stops a few steps from min/max values. Why is that?

I've tried all sorts of things, nothing works. I ended up adding 200 at the top value and subtracting 200 in the lower and to compensate, but that's is a hack and not a solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱的那么颓废 2024-08-25 07:55:59

在“幻灯片”回调中,尝试使用 ui.value 来获取值。这解决了我的问题。看
jQuery UI 滑块 - 无法滑动到 0 除非不按照答案,按照答案的评论。

In your 'slide' callback, try using ui.value to get the value. This solved my problem. See
jQuery UI slider - can't slide to 0 except don't go by the answer, go by the comment to the answer.

你列表最软的妹 2024-08-25 07:55:59

我意识到这个问题已经有 5 年历史了,但我今天刚刚遇到了类似的问题。我有一个有很多步长的短滑块,它从 0 到 1,步长为 0.01。滑块手柄会在碰到最外面的台阶之前撞到滑块的末端,因此我只能向下至 0.02 向上至 0.98。

如果有人遇到这个问题,一个快速的解决方法就是简单地让您的最小值和最大值比应有的值稍微远一点,并在用户滑过它们时调整您的值。

('.slider-container').slider({
                min: -0.02, max: 1.02, step: 0.01, slide: function () {

                    // make values below 0 and over 1 snap back
                    if ($(this).slider('value') < 0) {
                        $(this).slider('value', 0);
                    }

                    if ($(this).slider('value') > 1) {
                        $(this).slider('value', 1);
                    }
});

I realise this question is 5 years old but I just encountered a similar problem today. I had a short slider with many steps, it went from 0 to 1 with steps of 0.01. The slider handle would bump into the ends of the slider before hitting the outermost steps, so I could only go down to 0.02 and up to 0.98.

If anyone runs into this problem, a quick work-around is to simply make your min and max values go a little further than they should and adjust your value if the user slides past them.

('.slider-container').slider({
                min: -0.02, max: 1.02, step: 0.01, slide: function () {

                    // make values below 0 and over 1 snap back
                    if ($(this).slider('value') < 0) {
                        $(this).slider('value', 0);
                    }

                    if ($(this).slider('value') > 1) {
                        $(this).slider('value', 1);
                    }
});
咋地 2024-08-25 07:55:59

我对这些设置也有类似的问题

min: 35000.74
max: 150000
step: 1 //(default, did not actually change it)

,滑块最多只能达到 149999.74。当然,就我而言,问题是给定步骤 1 和未均匀划分为这些步骤的范围,滑块永远无法达到最终值之一。

将分钟更改为 35000 (Math.floor()),一切都非常顺利。

I had a similar problem with these settings

min: 35000.74
max: 150000
step: 1 //(default, did not actually change it)

and the slider only went as far as 149999.74. Of course, in my case the problem was that given the step 1 and a range that does not divide evenly into these steps, one of the end values could never be reached with a slider.

Changed the min to be 35000 (Math.floor()) and everything worked like a charm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文