zarocknz/javascript-winwheel

I need to center the segement pointer when its stop

Closed this issue · 1 comments

i need to set like this when its stop spining then its wheel come on center like not any different engle

Hello @mehuljariwala

There is no built in function for that, so the way to do this is to add this function to your html page...

// This function returns the center angle of the specified segment.
function getCenterForSegment(segmentNumber)
{
    var stopAngle = 0;

    if (segmentNumber)
    {
        if (typeof theWheel.segments[segmentNumber] !== 'undefined')
        {
            var startAngle = theWheel.segments[segmentNumber].startAngle;
            var endAngle = theWheel.segments[segmentNumber].endAngle;
            var range = (endAngle - startAngle);

            if (range > 0)
            {
                stopAngle = Math.floor(startAngle + range / 2);
            }
        }
    }
    
    return stopAngle;
}

Then in the code which sets the stopAngle before the spinning starts, instead of calling getRandomForSegment as seen in the tutorial http://dougtesting.net/winwheel/docs/tut14_setting_the_prize call the getCenterForSegment function instead passing in the segment number

// Set the stopping location to the center of a segment by calling the function below.
theWheel.animation.stopAngle = getCenterForSegment(3);

Cheers,
DouG.