0

I am trying to make a custom cursor for a website, which when clicked, anywhere on the page, the cursor changes to another image, until the button is unclicked when it will revert back to the original cursor.

body {
    cursor: url('images/cursor.png'), auto;
}
SirArchibald
  • 476
  • 2
  • 7
  • 23
  • Does this answer your question? [Using external images for CSS custom cursors](https://stackoverflow.com/questions/18551277/using-external-images-for-css-custom-cursors) – Ron May 05 '20 at 20:02

3 Answers3

1

You could simply use an onclick event listener on the body itself.

document.body.onmousedown = () => {
  document.body.style.cursor = "not-allowed"
}

document.body.onmouseup = () => {
  document.body.style.cursor = `pointer`
}
body {
  height: 100vh;
  background: aliceblue;
  cursor: pointer;
}
The Fool
  • 16,715
  • 5
  • 52
  • 86
1

Use :active on the html element:

html:active {
    cursor:pointer; /* url('images/cursor.png') */
}

html {
  min-height:100%;
}
<h1>title</h1>
<p>some text</p>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
0
<html>
<head>
<style>
.default_cursor {
    cursor: url('images/default.gif'), auto;    
}
.changed_cursor{
    cursor: url('images/changed.gif'), auto;
}
</style>
</head>

<body id="body" class="default_cursor">
Content Here

<script>
document.addEventListener("click", function(){
  document.getElementById("body").classList.toggle("changed_cursor"); //Toggle cursor.
});
</script>

</body>

</html>
Adeel Tahir
  • 203
  • 2
  • 9