Created
April 26, 2016 12:54
-
-
Save haydenbleasel/8af3d1aab8c8591cb39f36e049b4eabf to your computer and use it in GitHub Desktop.
Animated strikethrough on hover
This file contains 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
$('a').addClass('strikethrough').hover( | |
(e) => $(e.target).stop().addClass('mouseenter'), | |
(e) => { | |
$(e.target).stop().removeClass('mouseenter').addClass('mouseleave'); | |
setTimeout(() => { | |
$(e.target).stop().removeClass('mouseleave').addClass('no-transition'); | |
}, STIKETHROUGH_DURATION - STIKETHROUGH_OFFSET); | |
setTimeout(() => { | |
$(e.target).stop().removeClass('no-transition'); | |
}, STIKETHROUGH_DURATION + STIKETHROUGH_OFFSET); | |
} | |
); |
This file contains 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
a.strikethrough { | |
position: relative; | |
overflow: hidden; | |
display: inline-block; | |
line-height: normal; | |
vertical-align: text-bottom; | |
border: none; | |
padding: 0; | |
color: #999; | |
&:after { | |
content: ""; | |
display: block; | |
position: absolute; | |
top: 50%; | |
left: 0; | |
width: 100%; | |
background: #000; | |
height: 1px; | |
transform: translateX(-110%); | |
transition: transform 0.3s ease-in-out; | |
} | |
&.mouseenter { | |
color: #000; | |
&:after { | |
transform: translateX(0); | |
} | |
} | |
&.mouseleave:after { | |
transform: translateX(110%); | |
} | |
&.no-transition:after { | |
transition: none; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment