使用jQuery延迟图像加载 [英] Delay image loading with jQuery

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

问题描述

我有一个有几个画廊的页面,包括手风琴和滑块。问题是页面永远加载。有没有一种方法可以在一段代码中包装一个图像,或者应用一个类来强制它只在其他所有东西被加载后加载?

I have a page with several galleries including accordions and sliders. The problem is that the page takes forever to load. Is there a way of wrapping an image in a bit of code or applying a class to it to force it to load only after everything else is loaded?

推荐答案

当然可以。使用#替换您的img src属性,并添加一个自定义属性,如下所示:

Sure you can. Replace your img src attributes with a "#", and add a custom attribute, something like this:

<img src="#" delayedsrc="http://mydomain.com/myimage.png"/ >

然后,当您的网页加载时,添加一个javascript行,这个想法):

Then, add a javascript line when your page loads that does something like this (untested, but you get the idea):

$('img').each(function(){
  $(this).attr('src', $(this).attr('delayedsrc'));
});

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

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