简体   繁体   English

带有缩放标尺作为高度选择器的jQuery UI滑块

[英]jQuery UI slider with scaled ruler as height selector

I'm trying to work out the math on this sort of tricky input for a height selector. 我正试图在高度选择器的这种棘手的输入上计算出数学。

Basically - I have a jQuery UI slider to select a height. 基本上 - 我有一个jQuery UI滑块来选择高度。 It increments in inches and has a min of 0 and a max of 120 (10' tall). 它以英寸为单位递增,最小值为0,最大值为120(10英尺)。

As the user moves the slider, a corresponding ruler graphic moves. 当用户移动滑块时,相应的标尺图形移动。

I've set up a jsfiddle with what I have thus far here: http://jsfiddle.net/x57Rw/ 我已经在这里建立了一个jsfiddle: http//jsfiddle.net/x57Rw/

You can see my math is a bit off there. 你可以看到我的数学有点偏僻。 I know I need to scale the offset of the ruler graphic, but can't quite wrap my head around it. 我知道我需要缩放标尺图形的偏移量,但不能完全绕过它。 Basically looking for what I need to adjust to get the ruler to match (fairly) correctly with the slider input. 基本上寻找我需要调整以使标尺与滑块输入正确匹配(相当)。 It doesn't have to be totally exact but as close as possible. 它不必完全准确,但尽可能接近。 Any help would be greatly appreciated! 任何帮助将不胜感激!

Your slider needs to be brought down a bit with a margin to align with the bottom of the ruler like so: 您的滑块需要稍微降低一点,以便与标尺的底部对齐,如下所示:

        #height-slider.ui-slider-vertical .ui-slider-handle {
            left: -.8em;
            margin-bottom: -16px;
            ...
        } 

And you should be dividing by 144, not by 120 as your ruler image actually contains 144 inches, and your slider should be set to a max of 144 as well: 你应该除以144,而不是120,因为你的标尺图像实际上包含144英寸,你的滑块也应设置为最大144:

function animateRulerOffset(sliderValue) {
    pixelOffset = 622-((sliderValue*622)/144);
    ...
}

If you truly want only 120 inches, then your ruler image needs to be revised to end at 10 feet. 如果你真的只想要120英寸,那么你的标尺图像需要修改为以10英尺结束。

See http://jsfiddle.net/x57Rw/14/ http://jsfiddle.net/x57Rw/14/

Ruler's height is 744px, and it has 12'. 标尺的高度为744px,它有12'。

The max is 10', so we have to remove 2'->744*2/12 px (well, we add them because after that we multiply for -1). 最大值是10',所以我们必须删除2' - > 744 * 2/12 px(好吧,我们添加它们因为之后我们乘以-1)。

Then, we need a percentage. 然后,我们需要一个百分比。 The max is 120, so 1-sliderValue/120 (well, it's a per one, not percentage). 最大值是120,所以1-sliderValue / 120(好吧,它是每个,不是百分比)。

This percentage multiplies ruler's height minus ruler container's height. 此百分比乘以标尺的高度减去标尺容器的高度。 But we removed 744*2/12px, so we have to add it here too (well, its subtraction because after that we multiply for -1): 但是我们删除了744 * 2 / 12px,所以我们也必须在这里添加它(好吧,它的减法因为之后我们乘以-1):

pixelOffset = (744-112-744*2/12)*(1-sliderValue/120)+744*2/12;

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

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