多个 jQuery-UI 滑块的合计
我正在尝试实现一个有 4 个 jQuery-UI 滑块的页面,并且我想让所有 4 个滑块的总和永远不会超过 400。
我不介意采用哪种方式实现,它可以从 0 开始,一旦您更改 1 个滑块,剩余的可用总数就会减少,或者将滑块设置为超过最大值,则会减少其他滑块上的值。
PS 滑块以 10 为增量移动。
所有想法和想法均以 10 为增量。欢迎提出建议,如果您想测试,我已经设置了 jsFiddle 。
I'm trying to implement a page where there are 4 jQuery-UI sliders, and I want to make it so the combined total of all 4 sliders will never go over 400.
I don't mind which way this is implemented, it can be from a 0 start, and as soon as you change 1 slider, the remaining available total decreases or setting a slider past the maximum, decreases the values on the other sliders.
P.S. The sliders go in increments of 10.
All ideas & suggestions are welcome, and I've set up a jsFiddle if you'd like to test.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
好了,开始吧:
这是一个简单的演示:http://jsfiddle.net/yijian /Y5ZLL/4/
Well here ya go:
Here's a simple demo of this: http://jsfiddle.net/yijiang/Y5ZLL/4/
对上述答案进行了更新版本,以显示 100% 的百分比。因此,当您向上调整一个滑块时,另外两个滑块就会减小,从而使每个滑块的百分比加起来达到 100%。还可以轻松设置初始值
JSfiddle
Made an updated version of the above answer to show percentages of 100%. So as you adjust one slider up, the other two decrease making the percentage of each slider add up to 100%. Also made it easy to set initial values
JSfiddle
我发现当其他滑块(除了您正在移动的滑块之外的滑块)四处移动时,会分散注意力。我还修改了 Yi Jiang 小提琴,现在只需让它在达到总计 400 时停止即可。如果您希望该滑块走得更高,您首先必须降低其他一个滑块,就像第一个滑块一样,但它使滑块相对于总体保持不变。
这意味着当一个滑块处于 25% 且另一个滑块处于 50% 时,它们看起来分别为 25 和 50。
JSfiddle
I found when the other sliders (the ones other than the one you're moving) move around, it's distracting. I've also modified the Yi Jiang fiddle to now simply have it stop when you reach a total of 400. If you want that slider to go higher, you'll first have to lower one of the other ones much like how the first one, but it keeps the slider relative to the overall total.
This means that when you have one slider at 25% and another at 50%, they look like they are at 25 and 50 respectively.
JSfiddle
这些答案中没有一个对于以任何有效的方式改变滑块之间的关系是最有效的......他们中的大多数在计算中遗漏了一个或多个,或者不尊重总体限制,我需要一些东西允许用户在 HTML5 游戏中选择他们的筹码,所以如果其他人遇到类似的问题,我想出了这个...如果您不需要将其与更改投注筹码之类的东西联系起来,那么只需取出停止选项或更改它以满足您的需要
Not a single one of these answers was the least bit effective for changing sliders in relationship to each other in any effective way...most of them left one or more out of the calculations or did not respect the overall limit , I needed something for allowing a user to pick their chips in an HTML5 game so I came up with this if anyone else ever has a similar issue... if you don't need to tie it to something like changing betting chips then just take out the stop option or change it to suit your needs
这篇文章是我努力构建这个的一个很好的起点,希望它对其他人有帮助。 https://codepen.io/jmester13/pen/jOEyNEe
This thread was a great launching point for me to work towards building this, hope it helps others. https://codepen.io/jmester13/pen/jOEyNEe
这对我来说是一次很好的经历,我希望它对其他人也有帮助。
It was a good experience for me.I hope it will also helpful for others.