如何在加载页面时同步网站内容 [英] how to synchronize web site content while loading page
问题描述
我希望同步网站,例如首次加载页面时会加载内容然后是图片,然后是内容然后是其他内容。
I want to synchronize web site like when page load first it will load content then images then flash content then another content.
就像我在< a href =http://gmailblog.blogspot.com/ =nofollow> http://gmailblog.blogspot.com/ [查看图片如何加载]
Like i have seen the same at http://gmailblog.blogspot.com/ [ see how images load ]
有没有办法实现?任何链接或源代码将不胜感激。
Is there any way to achieve? Any link or source code would be appreciated.
推荐答案
您可以通过使用JS控制来同步页面上所有元素的加载。例如:在内容之后加载图像的一种策略是:
You can synchronize loading of all elements on your page by controlling it using JS. For ex: one strategy to load images after content would be:
a)在你的html中,而不是在src属性中,指定另一个属性中的图像位置,比如说'ISRC'。
a) In your html, instead of in the src attribute, specify the image location in another attribute, say 'isrc'.
b)在你的onload回调中(假设你正在使用jQuery):
b) Inside your onload callback (assumes you're using jQuery):
var loadCounter = 0;
$('img').each(function() {
if($(this).attr('isrc')) {
this.onload = function() {
loadCounter++;
if($('img[isrc]').length == loadCounter) {
// .. proceed to loading other stuff like flash etc..
}
}
$(this).attr('src', $(this).attr('isrc')); // load the image
}
});
这篇关于如何在加载页面时同步网站内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!