admin管理员组文章数量:1332865
I know how to create custom cursors,
cursor: url('custom.svg'), default;
But how do you attach an icon to a existing pointer 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?
Share Improve this question edited Oct 27, 2017 at 10:24 semirturgay 4,2013 gold badges31 silver badges50 bronze badges asked Oct 27, 2017 at 10:13 user3607282user3607282 2,5556 gold badges37 silver badges65 bronze badges 1- 2 You can make your own icon and replace the default one. Have a look at jsfiddle/wNKcU/5 – Ali Zia Commented Oct 27, 2017 at 10:15
2 Answers
Reset to default 5you 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./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. 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./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn./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>
本文标签: javascriptHow to attach an icon to a cursorStack Overflow
版权声明:本文标题:javascript - How to attach an icon to a cursor? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742286324a2446994.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论