Skip to content

Commit

Permalink
Fix gijsroge#55 - Cannot read property 'x'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanarbely authored Feb 7, 2021
1 parent 5998f49 commit 8f52cd9
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/tilt.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,17 @@
const height = $(this).outerHeight();
const left = $(this).offset().left;
const top = $(this).offset().top;
const percentageX = (this.mousePositions.x - left) / width;
const percentageY = (this.mousePositions.y - top) / height;
// x or y position inside instance / width of instance = percentage of position inside instance * the max tilt value
const tiltX = ((this.settings.maxTilt / 2) - ((percentageX) * this.settings.maxTilt)).toFixed(2);
const tiltY = (((percentageY) * this.settings.maxTilt) - (this.settings.maxTilt / 2)).toFixed(2);
// angle
const angle = Math.atan2(this.mousePositions.x - (left+width/2),- (this.mousePositions.y - (top+height/2)) )*(180/Math.PI);
// Return x & y tilt values
return {tiltX, tiltY, 'percentageX': percentageX * 100, 'percentageY': percentageY * 100, angle};
try {
const percentageX = (this.mousePositions.x - left) / width;
const percentageY = (this.mousePositions.y - top) / height;
// x or y position inside instance / width of instance = percentage of position inside instance * the max tilt value
const tiltX = ((this.settings.maxTilt / 2) - ((percentageX) * this.settings.maxTilt)).toFixed(2);
const tiltY = (((percentageY) * this.settings.maxTilt) - (this.settings.maxTilt / 2)).toFixed(2);
// angle
const angle = Math.atan2(this.mousePositions.x - (left+width/2),- (this.mousePositions.y - (top+height/2)) )*(180/Math.PI);
// Return x & y tilt values
return {tiltX, tiltY, 'percentageX': percentageX * 100, 'percentageY': percentageY * 100, angle};
} catch(e){}
};

/**
Expand Down Expand Up @@ -205,7 +207,6 @@
'transform-origin': '0% 0%',
'opacity': '0',
});

};

/**
Expand Down Expand Up @@ -302,4 +303,4 @@
$('[data-tilt]').tilt();

return true;
}));
}));

0 comments on commit 8f52cd9

Please sign in to comment.