NigelOToole / direction-reveal

Detects the direction a user enters or leaves an element allowing you to reveal or hide content based on this direction.
http://nigelotoole.github.io/direction-reveal/
MIT License
524 stars 39 forks source link

Direction calculation #7

Closed WTVader closed 5 years ago

WTVader commented 5 years ago

The calculation for x/y (line 33, 34 in direction-reveal.js) is not correct. The right parenthesis for the normalization is set wrong. Correct calculation: let x = (e.pageX - position.x - (w / 2)) (w > h ? (h / w) : 1); let y = (e.pageY - position.y - (h / 2)) (h > w ? (w / h) : 1); This causes a correct normalization for aspect ratios of the hovered element not equal 1, and subsequently the correct calculation of the direction.

NigelOToole commented 5 years ago

Thanks this has been corrected.