用jQuery预加载背景图片? [英] Preload background images with jQuery?

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

问题描述

我有一个div,当前已将其设置为不显示,该div的背景图片约为5000px宽,2000px高.

I have a div thats currently set to display none, The Div has a background image that is approx 5000px wide, 2000px high.

我只在图像很大的情况下用jQuery单击按钮来切换div显示样式,然后div加载,然后图像加载1/2秒.有什么功能可以显示预加载器,直到图像准备好然后显示它?

I toggle the div display attirbute with jquery on a button click only with the image being so big the div loads and the image loads 1/2 seconds afterwards; is there a function where I can show a preloader until the image is ready and then display it?

谢谢

推荐答案

尝试使用本机javascript的Image对象预加载图像.

Try to use native javascript's Image object to preload the image.

还考虑通过制作例如瓷砖来避免在网络上使用如此大的图像.

Also consider about to avoid using such huge images on the web by making tiles for example.

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

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