I have a set of buttons shown on the screen. I am trying to implement a function which executes upon hovering on a button (having a class 'button').
This function needs to display the mouse pointer at the center of the button, meaning that whilst the actual mouse pointer is on the button, the mouse pointer is displayed in the center of the button. I tried using the RequestPointerLock
API but this hides the mouse pointer whereas I want it to be displayed and I believe it only works with the event handler onclick
.
This is what I've done so far:
var buttons = document.getElementsByClassName('button');
buttons.requestPointerLock = buttons.requestPointerLock || buttons.mozRequestPointerLock;
document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock;
document.addEventListener('pointerlockchange', lockChangeAlert, false);
document.addEventListener('mozpointerlockchange', lockChangeAlert, false);
function lockChangeAlert()
{
if (document.pointerLockElement === buttons || document.mozPointerLockElement === buttons)
{
console.log('The pointer lock status is now locked');
document.addEventListener("mousemove", updatePosition, false);
} else
{
console.log('The pointer lock status is now unlocked');
document.removeEventListener("mousemove", updatePosition, false);
}
}
function updatePosition(e)
{
}
buttons.onclick = function()
{
buttons.requestPointerLock();
}
Any ideas on how I can implement this please?