Hi, Do you think about how you can create a custom cursor for your website?
This section will show you how to create custom cursors quickly and easily. We must take simple step (Create a HTML file and paste the codes below into it)
<div class="mouse" id="mouse">
<img src="https://i.postimg.cc/NFx1b2f7/pack2586.png" alt="">
</div>
<style>
body,
html {
width: 100%;
height: 100%;
overflow: hidden;
}
* {
cursor: none;
}
.mouse {
width: 20px;
height: 20px;
background-color: none;
position: absolute;
top: 0;
left: 0;
z-index: 1000;
}
.mouse img {
width: 40px;
}
</style>
<script>
document.onmousemove = function (e) {
var mouse = document.getElementById("mouse");
console.log(mouse.style);
mouse.style.left = e.pageX + 1 + "px";
mouse.style.top = e.pageY + 1 + "px";
}
</script>
Top comments (8)
I thought I'd quickly make an example of each method the first is what you've done in this post and the second is using css only.
I've made it so when the mouse is hovering the button the button goes green.
Thank you for your comment
Thanks for the article and this comment.
The cursor property in css takes a URL for an image. Using JavaScript for this isn't great for performance.
developer.mozilla.org/en-US/docs/W...
Just use with caution so you don't confuse the user, and don't forget to use the coordinates for a better clicking experience.
Thanks for sharing this! Is very useful!
So on touch devices this is a terrible user experience. Also changing your cursor is a terrible user experience from 2000/2010.