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?
-
There is a possibility to get the pointer location but not to manipulate it.jdickel– jdickel2020-07-25 10:45:24 +00:00Commented Jul 25, 2020 at 10:45
-
Read up for that on: stackoverflow.com/questions/7790725/…jdickel– jdickel2020-07-25 10:46:12 +00:00Commented Jul 25, 2020 at 10:46
-
One thing you could do though is to hide the cursor and draw a fake one that you can control.Kaiido– Kaiido2020-07-25 11:34:56 +00:00Commented Jul 25, 2020 at 11:34
Add a comment
|
2 Answers
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>