Well, i am trying to make follow an element the mouse cursor. and i actually did it. with this simple code here:
let element = document.getElementsByTagName('div')[0];
const moves = (e) =>{
element.style.left = e.pageX + 'px';
element.style.top = e.pageY + 'px';
}
document.addEventListener('mousemove', moves);
<div style="background-color:black;width:50px;height:50px"></div>
but I would like to put this code into an object. After some attempts I have come to this conclusion:
let navicella = {
navicella: document.getElementById('navicella'),
volo: function (e) {
console.log((e)); //problem here
this.navicella.style.left = (e).pageX + 'px';
this.navicella.style.top = (e).pageY + 'px';
this.document.addEventListener('mousemove', update);
}
};
function update() {
navicella.volo();
}
<body onload="update()">
<div id="navicella"></div>
And with it, problems came too. Any ideas?