Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 11-18-2008, 01:23 PM Preload Images Help
Super Talker

Posts: 106
Trades: 0
Hello i am currently pursuing web design. I found a very usefull preload image javascript on the web and decided to use it. The only problem is i have to type out every image path seperate. images/index_01.jpg,images/Index_02.jpg etc etc. When you have 50 or so images it gets too long. Would just writing images/*.jpg work? Here is the code that has the /images/*.jpg in:
Code:
<script>

/*
Preload images script
*/

var myimages=new Array()
function preloadimages(){
for (i=0;i<preloadimages.arguments.length;i++){
myimages[i]=new Image()
myimages[i].src=preloadimages.arguments[i]
}
}


//Enter path of images to be preloaded inside parenthesis. Extend list as desired.
preloadimages("images/*.jpg")
</script>
If it wont work is there any way that will?
fiveacehosting is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-18-2008, 02:42 PM Re: Preload Images Help
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
That won't work.
Are the images numbered? If so, and you know where the numbers stop, you could do something like this:
Code:
var images="";
for(var i=1; i<50; i++) {
var path=(i<10)?"/images/index_0":"/images/index_";
preloadimages(path+i+".jpg");
}
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 11-18-2008 at 02:49 PM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 11-19-2008, 12:10 PM Re: Preload Images Help
Super Talker

Posts: 106
Trades: 0
It seems to work. Its very fast. And in this template the images are numbered but all others they are named. Is there anyway to just preload all images for the images/ folder?
fiveacehosting is offline
Reply With Quote
View Public Profile
 
Old 11-19-2008, 01:03 PM Re: Preload Images Help
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
You could use a server side script to read all the files in that directory, then generate the JavaScript with the same server script to preload everything it finds.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 11-19-2008, 01:18 PM Re: Preload Images Help
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
However, if you're going to use a Server Language to read all the files, then write the JavaScript, you might as well just be using it to write HTML. The way I usually preload images, is with regular CSS:

CSS
Code:
.preload {
    position: absolute;
    left: -9999px;
}
HTML Code:
<div class="preload">
<!--put as many images as you like here-->
</div>
When images are positioned off-screen, the browser still loads them into memory.
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 11-19-2008 at 01:22 PM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 11-19-2008, 01:51 PM Re: Preload Images Help
Super Talker

Posts: 106
Trades: 0
The images are already in CSS.
fiveacehosting is offline
Reply With Quote
View Public Profile
 
Old 11-19-2008, 03:50 PM Re: Preload Images Help
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Huh? I'm not sure you understand me. "Images in CSS"? You mean as background images somewhere on the page? Anyhow, it doesn't matter how you use the images later, the method I described will preload images completely. Just place image tags into a div that puts everything off screen. Since you need a server language in order to access the file-system, it would be a better use of browser resources than using JavaScript, which isn't as fast as CSS.

I might add that I am somewhat sceptical that you would actually need to preload that many images. A common use of preloading is to save images in memory that will be used for rollovers later. If this is the case, you should read about CSS Sprites before you go preloading every image in your /images directory.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 11-20-2008, 02:34 PM Re: Preload Images Help
Super Talker

Posts: 106
Trades: 0
They are background images yes. And the reason i need to preload that many images is because i sliced in photoshop. Lots of slices
fiveacehosting is offline
Reply With Quote
View Public Profile
 
Old 11-20-2008, 03:12 PM Re: Preload Images Help
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
And the reason you need to preload them is?
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 11-20-2008, 04:28 PM Re: Preload Images Help
Super Talker

Posts: 106
Trades: 0
The website takes too long to download every page. Its alot quicker
fiveacehosting is offline
Reply With Quote
View Public Profile
 
Old 11-20-2008, 05:33 PM Re: Preload Images Help
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
So you want to trade one long-downloading page for several short ones? (be sure to put the script at the bottom of the page if this is the case).
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 11-20-2008 at 05:34 PM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to Preload Images Help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.92652 seconds with 12 queries