버튼 리플 애니메이션
17748 단어 csshtmlanimationjavascript
HTML
<button type="button" class="button red"> Ripple Effect </button>
<button type="button" class="button blue"> Ripple Effect </button>
<button type="button" class="button green"> Ripple Effect </button>
<button type="button" class="button orange"> Ripple Effect </button>
CSS/SCSS
CSS
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
flex-wrap: wrap;
align-content: center;
}
.button {
margin: 10px;
padding: 10px 20px;
position: relative;
overflow: hidden;
border-radius: 5px;
border: 2px solid;
background-color: transparent;
font-size: 14px;
font-weight: bold;
cursor: pointer;
}
.button.red {
color: red;
border-color: red;
}
.button.red .ripple_effect {
background-color: #ff000080;
}
.button.blue {
color: blue;
border-color: blue;
}
.button.blue .ripple_effect {
background-color: #0000ff80;
}
.button.green {
color: green;
border-color: green;
}
.button.green .ripple_effect {
background-color: #00800080;
}
.button.orange {
color: orange;
border-color: orange;
}
.button.orange .ripple_effect {
background-color: #ffa50080;
}
.button:focus {
outline: none;
}
.button .ripple_effect {
position: absolute;
border-radius: 50%;
transform: scale(0);
animation: ripple_effect 0.4s linear;
}
@keyframes ripple_effect {
to {
transform: scale(4);
opacity: 0;
}
}
SCSS
$color-primary: #eb4d4b;
$color-white: #ffffff;
$color-white-transparent: #ffffff54;
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
flex-wrap: wrap;
align-content: center;
}
.button {
margin: 10px;
padding: 10px 20px;
position: relative;
overflow: hidden;
border-radius: 5px;
border: 2px solid;
background-color: transparent;
font-size: 14px;
font-weight: bold;
cursor: pointer;
&.red {
color: red;
border-color: red;
.ripple_effect {
background-color: #ff000080;
}
}
&.blue {
color: blue;
border-color: blue;
.ripple_effect {
background-color: #0000ff80;
}
}
&.green {
color: green;
border-color: green;
.ripple_effect {
background-color: #00800080;
}
}
&.orange {
color: orange;
border-color: orange;
.ripple_effect {
background-color: #ffa50080;
}
}
&:focus {
outline: none;
}
.ripple_effect {
position: absolute;
border-radius: 50%;
transform: scale(0);
animation: ripple_effect 0.4s linear;
}
}
@keyframes ripple_effect {
to {
transform: scale(4);
opacity: 0;
}
}
자바스크립트
$(document).on('click', '.button', function(e) {
var element = document.createElement('DIV');
var current = $(this);
var offset = current.offset();
var max = Math.max(current.width(), current.height());
$(element).width(max);
$(element).height(max);
$(element).css({
'left': e.clientX - offset.left - max/2 + 'px',
'top': e.clientY - offset.top - max/2 + 'px'
});
current.prepend(element);
$(element).addClass('ripple_effect');
setTimeout(function(){
$(element).remove();
},500);
});
그게 다야.
여기에서 작업 데모를 확인할 수 있습니다. Codepen .
Reference
이 문제에 관하여(버튼 리플 애니메이션), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/raghavbhardwaj/button-ripple-animation-3k1j텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)