Normurod
Normurod

Reputation: 83

is it possible to prevent mouse cursor to leave a page when mouse down

It will be very good if you help me do this guys ! thanks a million in advance

//Something like this I am thingking

$(document).on('mousedown',function(){
    //code that prevents cursor leaving a page
});

Upvotes: 0

Views: 139

Answers (2)

Tony
Tony

Reputation: 744

There is a pointer lock API that should do what you are looking for using canvas.requestPointerLock || canvas.mozRequestPointerLock

There is a demo here

Check out the docs

Upvotes: 1

Louys Patrice Bessette
Louys Patrice Bessette

Reputation: 33943

I'm not sure it is possible to prevent mouse move.

But, an approach would be to track mouse x/y position and alert user when he's going off the page.

Look this SO answer about mouse tracking.

Upvotes: 0

Related Questions