So while making a website for trolls, I had the idea to make the website move a button that takes the user to another website and clicking it is the only way forward. Is there a way to check for the location of the cursor on the website to make the button change location, or is there a way to randomize the location of the cursor when it gets into a specific range?
Asked
Active
Viewed 48 times
1
-
There is a possibility to get the pointer location but not to manipulate it. – jdickel Jul 25 '20 at 10:45
-
Read up for that on: https://stackoverflow.com/questions/7790725/javascript-track-mouse-position – jdickel Jul 25 '20 at 10:46
-
One thing you could do though is to hide the cursor and draw a fake one that you can control. – Kaiido Jul 25 '20 at 11:34
2 Answers
3
You can detect the location of the mouse by listening to the onmousemove
event.
document.onmousemove = (ev) => {
if (ev.clientX < 100) {
document.querySelector('button').classList.add('moved');
} else {
document.querySelector('button').classList.remove('moved');
}
}
.moved {
transform: translate(200px);
}
<button>Click me!</button>

Olian04
- 6,480
- 2
- 27
- 54
1
all you need is onmousemove global handler. But you must be very careful - every even small move of mouse calls the event, so you function should not be very heavy. There is a way to prevent any problems by using throttling.

Tarukami
- 1,160
- 5
- 8