Created
October 15, 2015 07:16
-
-
Save halfzebra/2b261df37924a9936b29 to your computer and use it in GitHub Desktop.
JS Button Ripple Effect
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
.button { | |
background: #000000; | |
color: #ffffff; | |
line-height: 32px; | |
font-size: 16px; | |
max-width: 100px; | |
width: 100%; | |
text-align: center; | |
cursor: pointer; | |
position: relative; | |
overflow: hidden; | |
-webkit-touch-callout: none; | |
-webkit-user-select: none; | |
-khtml-user-select: none; | |
-moz-user-select: none; | |
-ms-user-select: none; | |
user-select: none; | |
} | |
.ripple { | |
position: absolute; | |
top: 0; | |
left: 0; | |
display: block; | |
width: 10px; | |
height: 10px; | |
margin-left: -5px; | |
margin-top: -5px; | |
background: #ffffff; | |
opacity: 0; | |
border-radius: 5px; | |
} | |
.ripple--animate { | |
-webkit-transition: -webkit-transform 300ms ease-in; | |
transition: transform 300ms ease-in; | |
-webkit-transform: scale(15); | |
-ms-transform: scale(15); | |
transform: scale(15); | |
opacity: 0.2; | |
pointer-events: none; | |
} |
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
<div class="button">Foo | |
<div class="ripple"></div> | |
</div> |
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
// For more reliable event support detection: http://stackoverflow.com/questions/16439161/how-to-support-transitionend-without-browser-sniffing | |
$('.button').on('mousedown', function (e) { | |
// Click coordinates. | |
var css = { | |
top: e.clientY, | |
left: e.clientX | |
}; | |
$('.ripple', this).css(css).addClass('ripple--animate'); | |
return true; | |
}); | |
$('.ripple').on('transitionend', function () { | |
$(this).removeClass('ripple--animate'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment