简体   繁体   English

如何将图标附加到光标?

[英]How to attach an icon to a cursor?

I know how to create custom cursors, 我知道如何创建自定义游标,

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

But how do you attach an icon to a existing pointer cursor? 但是如何将图标附加到现有指针光标?

看到图片

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> 

If you don't want to use a custom image for the cursor you could use JavaScript. 如果您不想为游标使用自定义图像,则可以使用JavaScript。 Here is an example with jQuery 这是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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM