ziiw
11/9/2016 - 11:59 AM

Detect rotation angle with Tween

Detect rotation angle with Tween

TweenMax.to(elem, duration, {
            rotationY: rotationY,
            ease: Power4.easeOut,
            onUpdateParams:["{self}"],
            onUpdate: (tween) => {
                let st = window.getComputedStyle(circle, null)
                let tr = st.getPropertyValue("-webkit-transform") ||
                        st.getPropertyValue("-moz-transform") ||
                        st.getPropertyValue("-ms-transform") ||
                        st.getPropertyValue("-o-transform") ||
                        st.getPropertyValue("transform") ||
                        "FAIL"

                let values = tr.split('(')[1].split(')')[0].split(',');
                let a = values[0];
                let b = values[1];
                let c = values[2];
                let d = values[3];

                let scale = Math.sqrt(a*a + b*b);
                let sin = b/scale;
                let angle = Math.round(Math.atan2(b, a) * (180/Math.PI));

                if(angle == 0){
                   // rotation angle = 0
                }else{
                   // rotation angle = 180
                }
            }
        })