50projects50days/button-ripple-effect/script.js

23 lines
627 B
JavaScript
Raw Normal View History

2020-10-26 14:40:00 +00:00
const buttons = document.querySelectorAll('.ripple')
buttons.forEach(button => {
button.addEventListener('click', function (e) {
2021-12-17 16:16:26 +00:00
const x = e.pageX
const y = e.pageY
2020-10-26 14:40:00 +00:00
const buttonTop = e.target.offsetTop
const buttonLeft = e.target.offsetLeft
const xInside = x - buttonLeft
const yInside = y - buttonTop
const circle = document.createElement('span')
circle.classList.add('circle')
circle.style.top = yInside + 'px'
circle.style.left = xInside + 'px'
this.appendChild(circle)
setTimeout(() => circle.remove(), 500)
})
})