背景图像中的淡入淡出
我有一个网页,使用大图像作为背景。 我希望在下载图像后使用 jQuery 来加载图像(基本上就是 bing.com 加载其背景图像的方式)。 这可以用 jQuery 实现吗? 如果是的话,有推荐的插件吗?
I have a web page that uses a large image for its background. I was hoping to use jQuery to load the image once it is downloaded (basically the way that bing.com loads its background image). Is this possible with jQuery? If so, is there a plugin that you would recommend?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以先加载图像,然后在加载完成后将其设置为背景图像。 这样浏览器将(希望)从缓存加载背景图像,而不是重新下载它。 正如您要求将其作为插件:
像这样使用它:
You could first load the image, and then, when it has finished loading, set it as background-image. That way the browser will (hopefully) load the background image from the cache instead of redownloading it. As you requested it as a plugin:
Use it like this:
这篇文章可能有用。 从那里复制:
HTML
CSS
Javascript
This article may be useful. Copying from there:
HTML
CSS
Javascript
您不能使用 CSS 背景图像,因为不可能将事件附加到图像的加载(据我所知)。
所以我会尝试一下,但还没有测试过:
HTML:
CSS:
Javascript:
You can't use CSS background images, because it's impossible to attach an event to the loading of the images (as far as I know).
So I'll give it a shot, but haven't tested it:
HTML:
CSS:
Javascript:
你可以使用以下技巧,抱歉,如果它有点脏。
脚本:
标记:
css:
希望这有帮助
一些示例:http://xgreen.co.uk/测试.htm
You can go with the following trick, sorry if its a bit dirty.
Script :
Markup :
css:
hope this helps
A little sample on : http://xgreen.co.uk/test.htm