![]() |
Question about preloading images
I'm working on a website with a slideshow (smoothDivScroll) and a lot of big images (about 50 photos of 50k each). This is all together more than 2500k so I want to use preloading of the images. Now I don't need to show all images right from the beginning, so I want to preload in steps: first the first 7 images which are necessary for the first look, than the next 7 when the page had loaded, then the next 7 after lets say 5 seconds etc. The images all have the same heigth of 500 px but different widths.
Basically (without the scrolling scripts) the html is as shown under. Can anybody help me with a script to load these images in interveals? Code:
<!DOCTYPE html> |
You don't want pre-loading, I think this is called 'lazy loading'.
I would use an onscroll handler that monitors the scroll speed, and when the speed falls below a certain level (or stops), determine which image placeholders are within the viewport, by comparing their offsetLeft/offsetTop values with the div's scrolled offsets and viewable area. Don't allow the calculations to be repeated until they are completed. Apply the appropriate image filename to each partially-visible placeholder. |
Hi Logic Ali,
Thanks for your prompt suggestion, but I thinking this is rather difficult. SmoothDivScroll allows the user to chose the scrolling direction and the sets of images he wants to see. It is not so important which images are on screen or probably coming on screen. The whole bunch has to be loaded in portions also to be sure the loading does not disturb the scrolling........ |
No I want preloading. LAs far as I know, lazy loading is based on a predictable show in which you know which slides are on the screen and which are coming on the screen. But with this smoothDivScroll the visitor can choose himself which slides he wants to see. So it is unpredictable. So that's why i choose for preloading.
|
I don't see anything wrong with your concept.
For starters only have those first 7 (or whatever number you decide on) images in that div. Luckily youe image names are all sequemtially numbered. You should specify the image height in the css...thus: Code:
#makeMeScrollable div.scrollableArea imgCode:
<body> |
i would avoid hard-coding a timeout like i see so far.
the problem with that is that you have no idea how long the images will take to load on the user's connection. if you go to fast, the last batch won't complete before the next one begins, and the page will grind to an unusable halt as it gets more and more backed-up. if you go to slow, the user will see blank spots, and may have to wait quite a while for the bottom images to appear. they should be loaded as quickly as possible, one at a time, without the potential of getting backed-up or stalling the browser's interface. a 1/10th second pause between images should do the trick. replace the src attrib on your late-load images with data-src, and use the script below. (avoid 404 image links) Code:
function convertOne(img){ |
| All times are GMT +1. The time now is 05:41 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.