How to attach icon to cursor?

I know how to create custom cursors,

cursor: url('custom.svg'), default;

But how do you attach an icon to an existing cursor cursor?

see picture

+4
source share
2 answers

you can try something like this :)

$(document).ready(function(){
  $('html').mousemove(function(e){
        var x = e.pageX - this.offsetLeft;
        var y = e.pageY - this.offsetTop;
        $('div.movablediv').css({'top': y,'left': x}); 
  });
});
.movablediv {width:25px; height:25px; position:absolute; border:solid 1px #000}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="movablediv"></div>
Run codeHide result
+4
source

If you do not want to use a custom cursor image, you can use JavaScript. Here is an example with jQuery

$(function() {
  $(document).mousemove(function(e) {
    var iconPosition = {
      top: e.pageY + 12,
      left: e.pageX + 12
    };
    $('.cursor-icon').offset(iconPosition);
  });
});
.cursor-icon {
  z-index: 1000;
  color: red;
  font-size: 2em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="cursor-icon"><i class="fa fa-heart" aria-hidden="true"></i></span>
Run codeHide result
+2
source

Source: https://habr.com/ru/post/1688280/


All Articles