简体   繁体   English

编号 slider 具有不同的最小最大值

[英]Number slider with different min max

I am trying to make an app where user slides the slider to select a compass direction, but we all know that sliders usually starts at 0 (left) and ends at N (right) .我正在尝试制作一个应用程序,用户将slider滑动到 select 指南针方向,但我们都知道滑块通常从0(左)开始并在N(右)结束。

I am trying to replicate this:我试图复制这个:指南针图像

Bottomline, I want the slider to start at 270(West) and the center should be 360 and 0(0 degree North) and next should be 0-90(North to East) then 90-180(East to South) and then 180-269(South to West)底线,我希望 slider 从270(West)开始,中心应该是3600(0 degree North) ,接下来应该是0-90(North to East) ,然后是90-180(East to South) ,然后是180-269(South to West)

Sorry for bad english, not native speaker.抱歉英语不好,不是母语人士。 If my explanation is not understandable, please refer to the image.如果我的解释无法理解,请参考图片。

If you start the slider on 270 degrees, then the center would be 90 degrees, because your compass is not centered on the slider range.如果您在 270 度上启动 slider,那么中心将为 90 度,因为您的指南针不在 slider 范围内。 You can use negative values to determine the applicable direction with some math:您可以使用负值通过一些数学来确定适用的方向:

 $('#slider-degrees').change(() => { let selection = parseInt($('#slider-degrees').val()); let degrees = (selection < 0)? (360 + selection): selection; $('#label-degrees').html(degrees); })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input id="slider-degrees" type="range" min="-90" max="269" value="-90"> <span id="label-degrees"></span>

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

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