| 116 | * @returns {{x: tilt value, y: tilt value}} |
| 117 | */ |
| 118 | const getValues = function () { |
| 119 | const width = $(this).outerWidth(); |
| 120 | const height = $(this).outerHeight(); |
| 121 | const left = $(this).offset().left; |
| 122 | const top = $(this).offset().top; |
| 123 | const percentageX = (this.mousePositions.x - left) / width; |
| 124 | const percentageY = (this.mousePositions.y - top) / height; |
| 125 | // x or y position inside instance / width of instance = percentage of position inside instance * the max tilt value |
| 126 | const tiltX = ( |
| 127 | this.settings.maxTilt / 2 - |
| 128 | percentageX * this.settings.maxTilt |
| 129 | ).toFixed(2); |
| 130 | const tiltY = ( |
| 131 | percentageY * this.settings.maxTilt - |
| 132 | this.settings.maxTilt / 2 |
| 133 | ).toFixed(2); |
| 134 | // angle |
| 135 | const angle = |
| 136 | Math.atan2( |
| 137 | this.mousePositions.x - (left + width / 2), |
| 138 | -(this.mousePositions.y - (top + height / 2)) |
| 139 | ) * |
| 140 | (180 / Math.PI); |
| 141 | // Return x & y tilt values |
| 142 | return { |
| 143 | tiltX, |
| 144 | tiltY, |
| 145 | percentageX: percentageX * 100, |
| 146 | percentageY: percentageY * 100, |
| 147 | angle, |
| 148 | }; |
| 149 | }; |
| 150 | |
| 151 | /** |
| 152 | * Update tilt transforms on mousemove |