将 Font Awesome 图标设置为光标 - 这可能吗? [英] Set Font Awesome icons as cursor - is this possible?

查看:26
本文介绍了将 Font Awesome 图标设置为光标 - 这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Font Awesome 有一个非常好的图标集合,可用于 Web 项目.我想使用其中一个图标作为光标(自定义光标).

Font Awesome has a very good collection of icons to be used in web projects. I want to use one of those icons as cursor (custom cursor).

据我了解,自定义光标需要一个图片网址,但我无法找到 Font Awesome 图标的图片网址.

In my understanding, Custom Cursors need an image url, but I am unable to find the image urls for Font Awesome icons.

推荐答案

知道了!

  1. 创建画布
  2. 在上面画上fa图标
  3. 改成base-64的图片url
  4. 在光标css样式上应用图片

我做了一个演示:http://jsfiddle.net/rqq8B/2/

// http://stackoverflow.com/questions/13761472/how-to-render-glyphs-from-fontawesome-on-a-canvas-element
// http://stackoverflow.com/questions/13932291/css-cursor-using-data-uri

$(function() {
    var canvas = document.createElement("canvas");
    canvas.width = 24;
    canvas.height = 24;
    //document.body.appendChild(canvas);
    var ctx = canvas.getContext("2d");
    ctx.fillStyle = "#000000";
    ctx.font = "24px FontAwesome";
    ctx.textAlign = "center";
    ctx.textBaseline = "middle";
    ctx.fillText("uf002", 12, 12);
    var dataURL = canvas.toDataURL('image/png')
    $('body').css('cursor', 'url('+dataURL+'), auto');
});

body {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>

这篇关于将 Font Awesome 图标设置为光标 - 这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆