admin管理员组文章数量:1388134
I have a 5MB Image that takes about 2-3 mins to load. While It loads, I want to have a loading screen. That loading screen will disappear after the images loaded. (The image is a sprite image; I use CSS to split it).
If this is possible, then how can I do it? If this isn't possible, then what other ways can I use to hide the loading of the image (or lower the image size)?
I have a 5MB Image that takes about 2-3 mins to load. While It loads, I want to have a loading screen. That loading screen will disappear after the images loaded. (The image is a sprite image; I use CSS to split it).
If this is possible, then how can I do it? If this isn't possible, then what other ways can I use to hide the loading of the image (or lower the image size)?
Share Improve this question edited May 4, 2012 at 9:29 No Results Found 103k38 gold badges198 silver badges231 bronze badges asked May 4, 2012 at 9:22 KevinT.KevinT. 3726 silver badges16 bronze badges 2- 2 I assume the image needs to be insanely large? – Alex Hadley Commented May 4, 2012 at 9:25
- 2 2-3 minutes for 5MB? Where are you located at? On the moon? – feeela Commented May 4, 2012 at 10:08
2 Answers
Reset to default 4That image is a sprite image.
I use css to split them.
Unless there is additional information which hasn't been stated, at 5MB you have defeated any advantages of a CSS sprite. Split it into separate files and lazy load on demand.
If you are using/can use jQuery this plugin does a nice job lazy loading.
Also ensure that you are using the best pression possible. Even if you must use lossless pression, there are still some gains which can be made by removing metadata from the image files.
"Save for Web" in Photoshop is great for balancing lossy pression (quality versus size) and also gives you the option to not embed metadata in image files. You can use a tool like Yahoo SmushIt if you don't have access to Photoshop.
Just hide the page/element behind some loading layer and remove that layer after the images are loaded:
<!-- within you site header -->
<script type="text/javascript">
/* display loader only if JavaScript is enabled, no JS-lib loaded at this point */
document.write('<div id="loader" style="display:table; position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10000; background: #fff;">'
+ '<div style="display:table-cell; vertical-align:middle; text-align: center;">'
+ 'loading…<br /><img src="icon.load.gif" />'
+ '</div></div>');
</script>
<!-- at the bottom of you HTML (right before closing BODY-tag) -->
<script src="jquery.min.js"></script>
<script type="text/javascript">
/* hide the loading-message */
$(window).load(function(){
$('#loader').fadeOut(500);
});
</script>
The trick is to use $(window).load()
as event handler, which does not get fired until all page contents are fully loaded.
本文标签: javascriptHow can I show a loading screen while a really large image is loadingStack Overflow
版权声明:本文标题:javascript - How can I show a loading screen while a really large image is loading? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744505348a2609561.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论