Best way to preload images

允我心安 提交于 2019-12-03 06:48:02
reporter

unfortunatly on this page there is no explaination, like jquery demos. But there is a link which is easy to oversee, so I post it for you here: imageQ-Demo. If you read the source code, the source of imageQ it self is nested within scripttag in the <head></head> section. I recommend that you move this source code into an extra file. The customised code ist nested within the <body></body> section. What you look for is

<script type="text/javascript">
    //Make an instance of imageQ
    imagesQueue = imagesQ;
    //Define the url of all your images
    imagesQueue.queue_images (['', '', ...]);
    //Start the preloading
    imagesQueue.process_queue();
</script>

hopefully it will helps you.

Btw, thank you for this link. ;-)

Your idea is good, when you want to have a fluent image change on-click. Altough script is coded in pure javascript (you can use more convinient approach: http://engineeredweb.com/blog/09/12/preloading-images-jquery-and-javascript) it shouldn't have such big influence on performance. Maybe the reason lays somewhere else. Maybe your images are too heavy...

Another solution besides javascript is using pure CSS approach and i suppose it would be much faster. Try to place all the images on single PNG and in CSS try to manipulate background-position value of the individual tabs. For example:

.tab {
    background-image:url('single.png');
}
#tab5 {
    background-position: 10px 20px;
}
#tab5:hover {
    background-position:10px 25px;
}

This way all images would be loaded once at one time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!