Skip to content

Instantly share code, notes, and snippets.

@brumm
Created May 25, 2018 19:36
Show Gist options
  • Save brumm/1ff59b5f11ab41e714c115adebef1812 to your computer and use it in GitHub Desktop.
Save brumm/1ff59b5f11ab41e714c115adebef1812 to your computer and use it in GitHub Desktop.
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