Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

I do not know why this happen

I want to apply a ripple effect to my div, but It isn't working as I expected it. There is a problem because I clicked double-clicked, and I do not know how to fix it.

<html>
<head>
<title></title>
<style>
*{
margin:0;
padding:0;
box-sizing:border-box;
}
.red{margin:50px;overflow:hidden;
height:56px;position:relative;
width:300px;
border:2px solid #000;
}
span{opacity:0;
position:absolute;
 height:100%;transform:translate(-50%,-50%);
 width:100%;border-radius:50%;
 background:red;
}
@keyframes  ripple{
0%{opacity:1;
height:0;
width:0;


}

100%{opacity:0;
width:800px;
height:800px;
}
}.j{
animation:1000ms ripple ;
}
</style>
</head>
<body>

<div class="red"  tabindex="0"></div>
<script>
const red = document.querySelector('.red')
red.addEventListener('click',function(){
const ripple = document.createElement('span')
red.appendChild(ripple)
let x = event.clientX - event.target.offsetLeft;//what is the difference between event and event.target
let y = event.clientY - event.target.offsetTop
ripple.classList.add('j')
ripple.style.left= x + "px"
ripple.style.top= y + "px"

setTimeout(function(){
ripple.remove()
},1000)
})
</script>
</body>
</html>