FlipperBizkut
08-31-2006, 05:03 PM
Lets say I have 5 images that I would like to show thumbnails for. When these thumbnails are clicked, a div with display set to 'none' should have its display set to 'block'. Within that newly visible div, should be the full sized image.
I have all that completed successfully. In fact, I have it set up to where it matters not how many images and all that. Here is the code:
function switchView(id) {
makeHidden(id);
showElement(id);
}
function makeHidden(id) {
var menu = document.getElementById('pictures');
var menuSubLists = menu.getElementsByTagName('div');
for (var i = 0 ; i < menuSubLists.length; i++){
var cycleMenuSubLists = menu.getElementsByTagName('div')[i];
if ((cycleMenuSubLists.getAttribute('id') != null) && (cycleMenuSubLists.getAttribute('id') != id)) {
hideElement(cycleMenuSubLists.getAttribute('id'));
}
}
}
function showElement(id) {
document.getElementById(id).style.display = document.getElementById(id).style.display == 'block' ? 'none' : 'block';
}
function hideElement(id) {
document.getElementById(id).style.display = 'none';
}
function switchLinks() {
if (document.getElementById) {
var menu = document.getElementById('pictures');
var menuItems = menu.getElementsByTagName('a');
for (var i = 0; i < menuItems.length; i++) {
var cycleMenuItems = menu.getElementsByTagName('a')[i];
if (cycleMenuItems.getAttribute('id') != null) {
cycleMenuItems.setAttribute('href', "javascript:switchView('" + cycleMenuItems.getAttribute('id') + "_sub');")
}
}
}
}
window.onload = switchLinks
the html:
<div id="pictures" align="center">
<a id="pic1" href="./dragon_3_1.htm"><img src="./Dragon_3_1_t.jpg" alt="" /></a>
<a id="pic2" href="./dragon_3_2.htm"><img src="./Dragon_3_2_t.jpg" alt="" /></a><br /><br />
<a id="pic3" href="./dragon_3_3.htm"><img src="./Dragon_3_3_t.jpg" alt="" /></a>
<a id="pic4" href="./dragon_3_4.htm"><img src="./Dragon_3_4_t.jpg" alt="" /></a>
<a id="pic5" href="./dragon_3_5.htm"><img src="./Dragon_3_5_t.jpg" alt="" /></a>
<div id="pic1_sub">
<img src="Dragon_3_1.jpg" alt="" />
</div>
<div id="pic2_sub">
<img src="Dragon_3_2.jpg" alt="" />
</div>
<div id="pic3_sub">
<img src="Dragon_3_3.jpg" alt="" />
</div>
<div id="pic4_sub">
<img src="Dragon_3_4.jpg" alt="" />
</div>
<div id="pic5_sub">
<img src="Dragon_3_5.jpg" alt="" />
</div>
</div>
The problem with this method is that all the fullsized images will be preloaded. This could cause long load times for slower connections, and possibly wasted bandwith if only part (or none) of the images are clicked for voewing of the full sized images.
What I want to do is basically the same thing as above but without preloading the fullsized images. Is there any way to do that?
I have all that completed successfully. In fact, I have it set up to where it matters not how many images and all that. Here is the code:
function switchView(id) {
makeHidden(id);
showElement(id);
}
function makeHidden(id) {
var menu = document.getElementById('pictures');
var menuSubLists = menu.getElementsByTagName('div');
for (var i = 0 ; i < menuSubLists.length; i++){
var cycleMenuSubLists = menu.getElementsByTagName('div')[i];
if ((cycleMenuSubLists.getAttribute('id') != null) && (cycleMenuSubLists.getAttribute('id') != id)) {
hideElement(cycleMenuSubLists.getAttribute('id'));
}
}
}
function showElement(id) {
document.getElementById(id).style.display = document.getElementById(id).style.display == 'block' ? 'none' : 'block';
}
function hideElement(id) {
document.getElementById(id).style.display = 'none';
}
function switchLinks() {
if (document.getElementById) {
var menu = document.getElementById('pictures');
var menuItems = menu.getElementsByTagName('a');
for (var i = 0; i < menuItems.length; i++) {
var cycleMenuItems = menu.getElementsByTagName('a')[i];
if (cycleMenuItems.getAttribute('id') != null) {
cycleMenuItems.setAttribute('href', "javascript:switchView('" + cycleMenuItems.getAttribute('id') + "_sub');")
}
}
}
}
window.onload = switchLinks
the html:
<div id="pictures" align="center">
<a id="pic1" href="./dragon_3_1.htm"><img src="./Dragon_3_1_t.jpg" alt="" /></a>
<a id="pic2" href="./dragon_3_2.htm"><img src="./Dragon_3_2_t.jpg" alt="" /></a><br /><br />
<a id="pic3" href="./dragon_3_3.htm"><img src="./Dragon_3_3_t.jpg" alt="" /></a>
<a id="pic4" href="./dragon_3_4.htm"><img src="./Dragon_3_4_t.jpg" alt="" /></a>
<a id="pic5" href="./dragon_3_5.htm"><img src="./Dragon_3_5_t.jpg" alt="" /></a>
<div id="pic1_sub">
<img src="Dragon_3_1.jpg" alt="" />
</div>
<div id="pic2_sub">
<img src="Dragon_3_2.jpg" alt="" />
</div>
<div id="pic3_sub">
<img src="Dragon_3_3.jpg" alt="" />
</div>
<div id="pic4_sub">
<img src="Dragon_3_4.jpg" alt="" />
</div>
<div id="pic5_sub">
<img src="Dragon_3_5.jpg" alt="" />
</div>
</div>
The problem with this method is that all the fullsized images will be preloaded. This could cause long load times for slower connections, and possibly wasted bandwith if only part (or none) of the images are clicked for voewing of the full sized images.
What I want to do is basically the same thing as above but without preloading the fullsized images. Is there any way to do that?