Created
June 7, 2017 04:43
-
-
Save Webnist/af374cf2dc9714c1ebbb51ae3386c7cd to your computer and use it in GitHub Desktop.
リップルエフェクトボタン ref: http://qiita.com/Webnist/items/fbe5bc75c568d0358b10
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
// クラス名rippleの要素を取得 | |
var ripples = $('.ripple'); | |
// クラス名rippleの要素があるかの判定 | |
if ( ripples[0] ) { | |
// クリックされた際の処理 | |
ripples.on('click', function(event) { | |
offset = $(this).offset(); // 絶対座標の取得 | |
w = $(this).outerWidth(); // 要素の幅を取得 | |
x = event.pageX - offset.left - (w / 2); // リップルの要素の X 座標を設定 | |
y = event.pageY - offset.top - (w / 2); // リップルの要素の Y 座標を設定 | |
// リップルの要素を設定 | |
html = $('<span>').css({ | |
'top' : y, | |
'left' : x, | |
'width' : w, | |
'height' : w | |
}).addClass('rp-effect').on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){ | |
// css の animation が終わったら各リップルの要素を削除 | |
$(this).remove(); | |
}) | |
// リップルの要素を追加 | |
$(this).append(html); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment