【问题标题】:Pre-Load Custom Cursors With Javascript使用 Javascript 预加载自定义游标
【发布时间】:2013-01-01 22:53:14
【问题描述】:

我已经能够在页面加载之前成功预加载图片库,但我想知道如何对自定义 cursor.cur 文件执行相同操作,因为它无法使用下面的图像方法,因为它无法理解 .cur 扩展名?

// Image Preloader
var pictures [
    "a.jpg",
    ..
    "z.jpg"
];

for (var i=0;i < pictures.length; i++){
    var img = new Image()
    img.src = pictures[i];
    img.onload = function(){
        updateProgress();
    }
}

【问题讨论】:

  • 尝试在 CSS 中对不可见(或非常小)的元素进行设置。我认为一旦加载了 CSS,就会加载光标。当然,您可以对 JQuery 执行相同的操作,尽管代码可能稍后执行。
  • 不会的。一旦被游标本身调用,它将加载。想想 :hover 在 css 中,图像只有在发生悬停时才会加载。

标签: javascript jquery preload mouse-cursor


【解决方案1】:

使用 AJAX .get() 加载 ico 文件并忽略响应。响应应该缓存在浏览器中。比如:

    $.get('/favicon.ico', function() {
        alert('Loading of ICO file completed!');
        // Do other processing here
    });  

http://jsfiddle.net/BGG2m/

【讨论】:

  • 效果很好,可以在预加载启动页面上预加载多个游标。顺便说一句,我的意思是在我的帖子中说 .cur 而不是 .ico。
猜你喜欢
  • 2012-10-02
  • 1970-01-01
  • 2010-10-09
  • 1970-01-01
  • 2019-02-19
  • 2017-08-06
  • 1970-01-01
  • 1970-01-01
  • 2017-12-21
相关资源
最近更新 更多