I've looked around for the answer and have found that I should use position: relative;
to remedy my situation. However, it does not appear to work in my case. I am using JQuery and AnimeJS. Essentially, what I am trying to accomplish is the Google ripple effect on their buttons with AnimeJS.
Thanks in advance if I do not respond immediately.
function ripple(event) {
//Find cursor position
var x = event.pageX,
y = event.pageY;
if ($(".ripple").length > 0) { //If there is already a div for the ripple
//Remove previous ripple
$(".ripple").remove();
$("div.btn").append("<div class='ripple'></div>"); //Append a div with the class ripple
$(".ripple").css({
"top": y - 20,
"left": x - 20
}); //Position the div so that it is on the cursor
var ripple = anime({ //Ripple Animation
targets: ".ripple",
opacity: {
value: [1, 0],
duration: 2000
},
scale: {
value: 10,
duration: 3000
},
});
$(".ripple").delay(2000).queue(function() {
$(this).remove();
}); //Delete div at the end of the animation
} else {
$("div.btn").append("<div class='ripple'></div>"); //Append a div with the class ripple
$(".ripple").css({
"top": y - 20,
"left": x - 20
}); //Position the div so that it is on the cursor
var ripple = anime({ //Ripple Animation
targets: ".ripple",
opacity: {
value: [1, 0],
duration: 2000
},
scale: {
value: 10,
duration: 3000
},
});
$(".ripple").delay(3000).queue(function() {
$(this).remove();
}); //Delete div at the end of the animation
}
}
html {
background: #d6d7d8;
height: 100%;
width: 100%;
}
body {
height: 100%;
width: 100%;
display: grid;
grid-template-columns: 2fr 1fr 2fr;
grid-template-rows: 2fr 1fr 2fr;
}
.btn {
grid-column-start: 2;
grid-column-end: 2;
grid-row-start: 2;
grid-row-end: 2;
background: #ff5722;
border-radius: 10px;
box-shadow: 0 10px 20px 4px #aaaaaa;
cursor: pointer;
overflow: hidden;
outline: none;
border: none;
position: relative;
}
.ripple {
pointer-events: none;
position: absolute;
border-radius: 50%;
height: 40px;
width: 40px;
background: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.2.0/anime.min.js"></script>
<div class="btn" onclick="ripple(event)"></div>