Created
May 25, 2018 19:36
-
-
Save brumm/1ff59b5f11ab41e714c115adebef1812 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AnimatedOverflow extends React.Component { | |
render() { | |
const { children } = this.props | |
return ( | |
<span | |
onMouseOver={({ target: node }) => { | |
const scrollDelta = node.offsetWidth - node.scrollWidth | |
if (scrollDelta < 0) { | |
const duration = 2000 * (node.scrollWidth / node.offsetWidth) | |
this.animation = node.animate( | |
[{ textIndent: '0px' }, { textIndent: `${scrollDelta}px` }], | |
{ | |
delay: 100, | |
endDelay: 100, | |
duration, | |
fill: 'forwards', | |
easing: 'ease-in-out', | |
} | |
) | |
} | |
}} | |
onMouseOut={() => { | |
if (this.animation) { | |
this.animation.playbackRate *= 3 | |
this.animation.reverse() | |
} | |
}} | |
> | |
{children} | |
</span> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment