停止使用javascript加载图片(延迟加载)? [英] Stop loading of images with javascript (lazyload)?

查看:103
本文介绍了停止使用javascript加载图片(延迟加载)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在dom就绪的情况下停止使用javascript加载图像,然后在需要时初始化加载,即所谓的图像延迟加载.像这样:

I am trying to stop the loading of images with javascript on dom ready and then init the loading whenever i want, a so called lazy loading of images. Something like this:



$(document).ready(function () {
  var images = $('img');
  $.each(images, function() {
    $(this).attr('src', '');
  });
});

这是行不通的(在ff3.5中进行了测试,野生动物园3-4).图像无论如何都被加载,我不明白.

This doesn't work (tested in ff3.5, safari 3-4). The images is getting loaded anyway, i dont get it.

例如,此插件www.appelsiini.net/projects/lazyload正在做同样的事情,在页面加载时删除了src属性.

For example this plugin, www.appelsiini.net/projects/lazyload, is doing the exact same thing, removing the src attribute on page load.

我想念什么?

我在此处添加了一个测试页面: http://dev.bolmaster2.com/dev/lazyload-test/ 我首先完全删除src属性,然后在5秒钟后将其与原始图像添加在一起.仍然不起作用,至少萤火虫说启动时会加载图像,萤火虫值得信任吗?

I added a test page here: http://dev.bolmaster2.com/dev/lazyload-test/ I first remove the src attribute completely, then after 5 seconds I add it with the original image. Still doesn't work, at least firebug says the images get loaded at start, is firebug to trust?

推荐答案

我认为问题在于您正在清空'img'属性,而不是'src'.

I think the problem is that you are emptying the 'img' attribute, not the 'src'.

如果您在本地页面上对此进行测试,则您的本地图像加载速度可能太快.或者,它们可能直接从浏览器缓存中获取.在清空图片的"src"之前,请尝试检查图片是否已加载.

If you are testing this on a local page, then your local images may be loading too fast. Or maybe they are taken directly from browser cache. Try checking if the image is already loaded before emptying its 'src'.

这篇关于停止使用javascript加载图片(延迟加载)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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