Fix mouse cursor gradient tracking demo

This commit is contained in:
Angelos Chalaris
2019-08-30 10:58:57 +03:00
parent 672068c920
commit d4661854db
3 changed files with 6 additions and 5 deletions

View File

@ -49,8 +49,9 @@ A hover effect where the gradient follows the mouse cursor.
```js
var btn = document.querySelector('.mouse-cursor-gradient-tracking')
btn.onmousemove = function(e) {
var x = e.pageX - btn.offsetLeft - btn.offsetParent.offsetLeft
var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
var rect = e.target.getBoundingClientRect()
var x = e.clientX - rect.left
var y = e.clientY - rect.top
btn.style.setProperty('--x', x + 'px')
btn.style.setProperty('--y', y + 'px')
}