How to calculate the angle of rotation of the nearest panel in the carousel

I have this carousel that rotates in 3D using -webkit-transform: rotateX(rotation in deg);. It has 10 panels, which means that every 36 degrees there is a panel with a center.

Now I'm trying to create an “snap to” effect caused by the event touchendby setting the closest panel centered in front.

My problem is that from an arbitrary rotation value, for example, -1820 degrees, how can I calculate which panel, or, more precisely, to what extent the nearest panel?

Hope this makes sense. A tip would be greatly appreciated.

+5
source share
2 answers

, , , wg3schools %.

: 5% 2 1

 var initialAngle= getAngle();  //let say it 1820 
 var closestPane= initialAngle%36; //which gives you 20.

, , ( A). (36-20 = 16), .

angle before ---- A ---- angle after
            20deg   16deg

,

+4

Danele B...

function snapToAngle(Angle) {
var deltaAngle = Math.abs(Angle)%36; 

    if (Angle >= 0) { 
       (deltaAngle <= 18) ? Angle -= deltaAngle : Angle+=36-deltaAngle;
    } else {
       (deltaAngle <= 18) ? Angle += deltaAngle : Angle -= 36-deltaAngle;
    }
return Angle;
}

, , , , .

0

All Articles