I wrote an image viewer here:
http://206.251.36.107/photographs/base. ... ber%202008But I have a problem. The photographs are large, like 250k each, and there are a lot of them. The thumbnails are less than 10k tho, and you can't view more than one full size at a time, so there is no way I want to preload all those images.
The problem is, the image doesn't always display at the first click.
<img src="longislandsound11-08/LongIslandSound11-08_405_thumb.jpg"
vspace=10 hspace=10
class="thumb"
id="longislandsound11-08/LongIslandSound11-08_405.jpg"
onmousedown="loadphoto('longislandsound11-08/LongIslandSound11-08_405.jpg')"
onclick="showphoto('East Hampton')">
-
- <img src="longislandsound11-08/LongIslandSound11-08_405_thumb.jpg"
- vspace=10 hspace=10
- class="thumb"
- id="longislandsound11-08/LongIslandSound11-08_405.jpg"
- onmousedown="loadphoto('longislandsound11-08/LongIslandSound11-08_405.jpg')"
- onclick="showphoto('East Hampton')">
-
is from the "page source"; the relevant js is:
function loadphoto(path) {
pic = new Image(); /* no var = global! */
pic.src = path;
}
function showphoto(cap) {
var h = document.getElementById('main').offsetHeight-20;
var w = document.getElementById('main').offsetWidth-20;
PhotoBox.width = pic.width;
PhotoBox.height = pic.height;
if (h < pic.height) {
PhotoBox.width = h/pic.height*pic.width;
PhotoBox.height = h;
}
if (w < pic.width) {
PhotoBox.width = w;
PhotoBox.height = w/pic.width*pic.height;
}
PhotoBox.src=pic.src;
Caption.textContent = cap;
}
-
- function loadphoto(path) {
- pic = new Image(); /* no var = global! */
- pic.src = path;
- }
-
- function showphoto(cap) {
- var h = document.getElementById('main').offsetHeight-20;
- var w = document.getElementById('main').offsetWidth-20;
- PhotoBox.width = pic.width;
- PhotoBox.height = pic.height;
- if (h < pic.height) {
- PhotoBox.width = h/pic.height*pic.width;
- PhotoBox.height = h;
- }
- if (w < pic.width) {
- PhotoBox.width = w;
- PhotoBox.height = w/pic.width*pic.height;
- }
- PhotoBox.src=pic.src;
- Caption.textContent = cap;
- }
-
The reason I used loadphoto/showphoto with mousedown/onclick is that it did correct the problem at home, but used via the net it does not (so I put "click TWICE on an image to load")*. However, loadphoto() completes since the caption will appear. In fact, it completes even if I use image.onLoad() as a condition -- and yet the pic NEVER appears.
Evidently it is loaded tho, because the second click (even a quick double click) will display it, and once you've viewed it once, it only requires a single click if you want to go back to a previously viewed picture.
MK

*actually, the problem is not perfectly consistent, and doing it this way does seem to improve the chances of success.
