延迟加载<img/>或背景图片

时间:2012-01-25 14:42:28

标签: html html5 jquery-ui

我的应用中有一个用户列表,一个jQuery-UI accordion。它看起来不错,但问题是,每个手风琴都包含用户的头像。

它曾经是一个之前,但现在我只是设置背景图像。到目前为止,很多用户都在网站上,由于这个页面现在是1 MB的数据,我觉得我应该减少。

是否有一种简单的方法可以确保图像只能在查看时加载?

2 个答案:

答案 0 :(得分:0)

这样的事情会起作用。如果是我,我会在DOM完成加载后加载它们。

$(this).on('click', function(event) {
    var img = document.createElement('img');
    img.src = 'http://...'; // Whatever the source is. I would store it in as data attribute in 'this'.
    this.appendChild(img);
})

答案 1 :(得分:0)

jquery有一个延迟加载插件, 这是演示http://www.appelsiini.net/projects/lazyload/enabled.html 你在找这样的东西吗?

相关问题