Gamehow JavaScript 微调器找不到 Value

Gameshow JavaScript spinner can't find Value

本文关键字:找不到 Value JavaScript Gamehow      更新时间:2023-09-26

我正在尝试获取微调器的结果。经过 6 个小时的调试和各种数学尝试,我似乎无法找到如何在每次旋转时获得微调器的值。它降落在什么DIV上?!

http://codepen.io/anon/pen/OMrOPe

最初我认为以下算法会起作用。

total_rotations = Get Total Degrees in rotations (including what was done historically.
total_rotations /  360 = _total_rotations_of_a_circle
value_to_subtract = Take the absolute value of _total_rotations_of_a_circle * 360
left_over_value_in_Degree = total_rotations - value_to_subtract
left_over_value_in_Degree/60 = result.

此算法仅在有时有效。我只是不确定如何做到这一点,任何提示都会有所帮助。

aoY 变量是由原始开发人员提出的,但我不知道如何使用该值来查找它指向的实际div。我在这里需要什么数学?

$('#wheel .sec').each(function(){
            var t = $(this);
            var noY = 0;
        var c = 0;
        var n = 700;    
        var interval = setInterval(function () {
            c++;                
            if (c === n) { 
                clearInterval(interval);                
            }   
            var aoY = t.offset().top;
            $("#txt").html(aoY);
            console.log(aoY);
            /*23.7 is the minumum offset number that 
            each section can get, in a 30 angle degree.
            So, if the offset reaches 23.7, then we know
            that it has a 30 degree angle and therefore, 
            exactly aligned with the spin btn*/
            if(aoY < 23.89){
                console.log('<<<<<<<<');
                $('#spin').addClass('spin');
                setTimeout(function () { 
                    $('#spin').removeClass('spin');
                }, 100);    
            }
        }, 10);
        $('#inner-wheel').css({
            'transform' : 'rotate(' + totalDegree + 'deg)'          
        });
        noY = t.offset().top;
    });
});

RobG 提出的公式是正确的:

Math.ceil((( totalDegree + 30 ) % 360) / 60)

您还必须考虑的事实是,每次连续播放的偏移量都会发生变化。为了解决这个问题,您可以简单地使用此公式:

offset = extraDegree MOD 60

然后,您可以将函数中的数字 30 替换为偏移变量:

Math.ceil((( totalDegree + offset ) % 360) / 60)

看到这个小提琴