Jquery 图像预加载器(我如何让loading.gif 更快地出现)

发布于 2024-07-29 04:09:20 字数 588 浏览 7 评论 0原文

我试图让 Jquery 图像预加载器启动“loading.gif”,并且图像预加载区域在页面打开时立即启动(如果这是一个合适的术语),我一直在尝试 javascript 放置和其他东西,但它总是加载不符合我的口味有点太晚了。

这是网址

http://eleven23.net/beta/work/web/ Lounge22-preload.php

我正在尝试一些变量,以使其加载速度更快,

我应该使用哪一个?

$(window).bind("加载", function() {

  • 或 -

$(文档).ready(function(){

另外,我将内联 javascript 放在 之前,希望这也能加快 jquery 的启动时间。

有什么建议吗?

Im attempting to get a Jquery image preloader to start the "loading.gif" and image preloading areas to start immediately on page open (if that's even a proper term) and I have been experimenting with javascript placement and other things, but it always loads a bit too late for my tastes.

Here is the URL

http://eleven23.net/beta/work/web/lounge22-preload.php

There are a few variables im experimenting with to get it to load faster

Which one should I use?

$(window).bind("load", function() {

  • or -

$(document).ready (function() {

Also Ive placed the inline javascript right before </body> hoping that would also speed the jquery start time.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

星軌x 2024-08-05 04:09:20

我使用旧的图像元素来缓存图像。 当它们加载时,我知道它们在浏览器缓存中。 如果我想确保它们在附近,我会将它们保存在一个不能超出范围的数组中。

var images = [];

// Preload a list of images with an optional callback as a final parameter.
function preload() {
    if ( arguments.length == 0 ) return;
    var waiting = arguments.length - 1,
        count = 0,
        callback = arguments[ arguments.length - 1 ];
    if ( typeof callback == "string" ) {
        callback = function() { };
        waiting++;
    }
    function loaded() {
        if ( ++count == waiting ) callback();
    }
    for ( var i = 0 ; i < waiting ; i++ ) {
        var image = new Image();
        image.onload = loaded;
        image.src = arguments[ i ];
    }
}

preload( "people.gif", "images/star.jpg", "/site/images/panorama.jpg", function() {
    doSomethingWithImages();
});

我很想知道使用图像元素的任何主要缺点。

我在 MDC 上找不到 Image 的原始文档,但这里有一些有关使用 Image 对象的当代文档。

https://developer.mozilla.org/en/Canvas_tutorial/Using_images

但是, object 早于 Canvas 和 HTML 5。它可以追溯到很久以前。

https:// web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-5214317.html

I've used the old-timey image element to cache images. When they load, I know they are in the browser cache. If I want to make sure they are around, I hold onto them in an array that can't go out of scope.

var images = [];

// Preload a list of images with an optional callback as a final parameter.
function preload() {
    if ( arguments.length == 0 ) return;
    var waiting = arguments.length - 1,
        count = 0,
        callback = arguments[ arguments.length - 1 ];
    if ( typeof callback == "string" ) {
        callback = function() { };
        waiting++;
    }
    function loaded() {
        if ( ++count == waiting ) callback();
    }
    for ( var i = 0 ; i < waiting ; i++ ) {
        var image = new Image();
        image.onload = loaded;
        image.src = arguments[ i ];
    }
}

preload( "people.gif", "images/star.jpg", "/site/images/panorama.jpg", function() {
    doSomethingWithImages();
});

I'd be curious to hear of any major drawbacks to using the image element.

I can't find the original documentation for Image at the MDC, but here is some contemporary documentation on using the Image object.

https://developer.mozilla.org/en/Canvas_tutorial/Using_images

But, the object predates Canvas and HTML 5. It goes way back.

https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-5214317.html

丢了幸福的猪 2024-08-05 04:09:20

一旦 DOM 加载并准备好进行操作, $(document).ready() 就会触发。 在这里添加加载图像,预加载大图像,然后再次删除加载图像并不能真正按照您想要的方式工作。

您需要将加载图像添加到标记中(以便立即渲染),然后预加载大图像,并在加载时隐藏/删除加载图像。

有一个关于使用简单插件预加载图像的很好的教程
此处

$(document).ready() fires once the DOM is loaded and ready to be manipulated. Adding the loading image here, pre-loading the large image and then removing the loading image again won't really work as you want it to.

You need to add the loading image to your markup (so it's rended immediately), then pre-load the large image and when loaded hide/remove the loading image.

There's a good tutorial on pre-loading images using a simple plugin
here.

一影成城 2024-08-05 04:09:20

嘿,您可以查看我编写的一个很棒的 jQuery 预加载器,它具有完整的回调、自动读取要预加载的图像以及大量动画缓动功能。 在这里查看:jQuery 预加载器

Hey, you can check out a great jQuery Preloader that I wrote with full callbacks, auto reading of images to preload, and a lot of easing in animations. Check it out here: jQuery Preloader

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文