HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 14th, 2009, 05:42 PM
rsdesign rsdesign is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 142 rsdesign User rank is Sergeant (500 - 2000 Reputation Level)rsdesign User rank is Sergeant (500 - 2000 Reputation Level)rsdesign User rank is Sergeant (500 - 2000 Reputation Level)rsdesign User rank is Sergeant (500 - 2000 Reputation Level)rsdesign User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 27 m 13 sec
Reputation Power: 16
JavaScript - Need help with javascript gallery thumbs

I am in final stages of a website development project that includes a small image thumbnail gallery for each product. Here is a link to one of the work-in-progress pages containing the gallery.
http://www.evolution-clothing.co.uk/develop/Men/item.asp?idRef=18
Here is the javascript I used for the gallery, I found it on the web, I know absolutely no javascript.
Code:
var lastID = 0;
function SelectImg(id) {
if (lastID > 0) {
document.getElementById(lastID).className = "thumbNormal";
}
document.getElementById(id).className = "thumbSelected";
document.getElementById(0).src = document.getElementById(id).src;
lastID = id;
}
function LoadTrigger() {
SelectImg(1);
}
window.onload = LoadTrigger;

followed by:
<img id=1 class="thumbNormal" src="productImages/card_c2.jpg" alt="Timberland zip cardigan" width="70" onclick="SelectImg(1)"/>
<img id=2 class="thumbNormal" src="productImages/card_c.jpg" alt="Timberland zip cardigan" width="70" onclick="SelectImg(2)"/>
<img id=3 class="thumbNormal" src="productImages/card_c1.jpg" alt="Timberland zip cardigan" width="70" onclick="SelectImg(3)"/>
<img id=0 src="">

The problem I am experiencing is in IE, there is pause before the main image is displayed, a missing image icon momentarily appears. On a couple of occasions the main image did not load at all.
Is there something wrong with this code? Or is there a really simple alternative script that will achieve the same effect but a bit more reliably?
many thanks in advance.

Reply With Quote
  #2  
Old October 19th, 2009, 06:06 PM
markoc's Avatar
markoc markoc is offline
Contributing User
ASP Free Regular (2000 - 2499 posts)
 
Join Date: Nov 2003
Location: UK
Posts: 2,255 markoc User rank is Captain (20000 - 30000 Reputation Level)markoc User rank is Captain (20000 - 30000 Reputation Level)markoc User rank is Captain (20000 - 30000 Reputation Level)markoc User rank is Captain (20000 - 30000 Reputation Level)markoc User rank is Captain (20000 - 30000 Reputation Level)markoc User rank is Captain (20000 - 30000 Reputation Level)markoc User rank is Captain (20000 - 30000 Reputation Level)markoc User rank is Captain (20000 - 30000 Reputation Level)markoc User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 3 Weeks 1 Day 23 h 7 m 29 sec
Reputation Power: 306
Need help with javascript gallery thumbs

you can do it either by creating a transparent gif and set the default image of 0 as that, or hide the image 0 until it loads the image to be displayed like:

Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title></title>
<script language="javascript">
<!--//
var lastID = 0;

function SelectImg(id) {
	if (lastID > 0) {
		document.getElementById(lastID).className = "thumbNormal";
	}
	
	document.getElementById(id).className = "thumbSelected";
	document.getElementById(0).src = document.getElementById(id).src;

	if (document.getElementById("fullDiv").style.visibility == "hidden") document.getElementById("fullDiv").style.visibility = "visible"
	lastID = id;
}
function LoadTrigger() {
	document.getElementById("fullDiv").style.visibility = "hidden";
	SelectImg(1);
}

window.onload = LoadTrigger;

//-->
</script>
<style type="text/css">
body 
{
	
}

.thumbNormal 
{
	border-top: solid 2px #000000;
	border-bottom: solid 2px #000000;
	border-left: solid 2px #000000;
	border-right: solid 2px #000000;
	padding-right: 5px;
}

.thumbSelected 
{
	border-top: solid 2px #ff0000;
	border-bottom: solid 2px #ff0000;
	border-left: solid 2px #ff0000;
	border-right: solid 2px #ff0000;
	padding-right: 5px;
}

#thumbDiv 
{
	height: 60px;
}
</style>
</head>
<body>
<div id="thumbDiv">
	<img id="1" name="1" class="thumbNormal" src="http://www.google.co.uk/intl/en_uk/images/logo.gif" alt="Timberland zip cardigan" width="70" onclick="javascript:SelectImg(this.name)" />
	<img id="2" name="2" class="thumbNormal" src="http://www.bbc.co.uk/home/release-36-2/img/new_logo.png" alt="Timberland zip cardigan" width="70" onclick="javascript:SelectImg(this.name)" />
	<img id="3" name="3" class="thumbNormal" src="http://www.google.co.uk/intl/en_uk/images/logo.gif" alt="Timberland zip cardigan" width="70" onclick="javascript:SelectImg(this.name)" />
</div>
<div id="fullDiv">
	<img id="0" />
</div>
</body>
</html>
__________________
Hope this advise helps.

If so please show your appreciation by adding reputation points (click gauge image on top right of this post and score).

Reply With Quote
  #3  
Old October 20th, 2009, 11:11 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 48th Plane (28500 - 28999 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 28,838 Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)  Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 3 Months 2 Weeks 1 Day 14 h 30 m 10 sec
Reputation Power: 2389
yes, the code is bad.

first of all, don't name things by numbers! that's the worst possible practice.

second, image with no "src" will cause the browser to fetch the "Not Found"
page from the server - you don't want it.

improved version of the code:
Code:
var lastID = "";
function SelectImg(id) {
	if (lastID.length > 0) {
		document.getElementById(lastID).className = "thumbNormal";
	}
	
	var oImage = document.getElementById(id);
	oImage.className = "thumbSelected";
	GetFullImage().src = oImage.src;
	lastID = id;
}

function GetFullImage() {
	var oFullImage = document.getElementById("FullImage");
	if (!oFullImage) {
		oFullImage = document.createElement("img");
		oFullImage.id = "FullImage";
		document.getElementById("FullImagePlaceholder").appendChild(oFullImage);
	}
	return oFullImage;
}

function LoadTrigger() {
	SelectImg("image1");
}
window.onload = LoadTrigger;

followed by:
<img id="image1" class="thumbNormal" src="productImages/card_c2.jpg" alt="Timberland zip cardigan" width="70" onclick="SelectImg(this.id)"/>
<img id="image2" class="thumbNormal" src="productImages/card_c.jpg" alt="Timberland zip cardigan" width="70" onclick="SelectImg(this.id)"/>
<img id="image3" class="thumbNormal" src="productImages/card_c1.jpg" alt="Timberland zip cardigan" width="70" onclick="SelectImg(this.id)"/>
<div id="FullImagePlaceholder"></div>

good luck, let us know how it goes.
Comments on this post
rsdesign agrees: Yes, I tried this code and it worked perfectly

Last edited by Shadow Wizard : October 20th, 2009 at 11:16 AM.

Reply With Quote
  #4  
Old October 22nd, 2009, 11:21 AM
rsdesign rsdesign is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 142 rsdesign User rank is Sergeant (500 - 2000 Reputation Level)rsdesign User rank is Sergeant (500 - 2000 Reputation Level)rsdesign User rank is Sergeant (500 - 2000 Reputation Level)rsdesign User rank is Sergeant (500 - 2000 Reputation Level)rsdesign User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 27 m 13 sec
Reputation Power: 16
Quote:
Originally Posted by Shadow Wizard
yes, the code is bad.

first of all, don't name things by numbers! that's the worst possible practice.

second, image with no "src" will cause the browser to fetch the "Not Found"
page from the server - you don't want it.

improved version of the code:
Code:
var lastID = "";
function SelectImg(id) {
	if (lastID.length > 0) {
		document.getElementById(lastID).className = "thumbNormal";
	}
	
	var oImage = document.getElementById(id);
	oImage.className = "thumbSelected";
	GetFullImage().src = oImage.src;
	lastID = id;
}

function GetFullImage() {
	var oFullImage = document.getElementById("FullImage");
	if (!oFullImage) {
		oFullImage = document.createElement("img");
		oFullImage.id = "FullImage";
		document.getElementById("FullImagePlaceholder").appendChild(oFullImage);
	}
	return oFullImage;
}

function LoadTrigger() {
	SelectImg("image1");
}
window.onload = LoadTrigger;

followed by:
<img id="image1" class="thumbNormal" src="productImages/card_c2.jpg" alt="Timberland zip cardigan" width="70" onclick="SelectImg(this.id)"/>
<img id="image2" class="thumbNormal" src="productImages/card_c.jpg" alt="Timberland zip cardigan" width="70" onclick="SelectImg(this.id)"/>
<img id="image3" class="thumbNormal" src="productImages/card_c1.jpg" alt="Timberland zip cardigan" width="70" onclick="SelectImg(this.id)"/>
<div id="FullImagePlaceholder"></div>

good luck, let us know how it goes.


Many thanks for these responses, I managed to find some good but admittedly more elaborate javascript with a couple of effect functions that I was able to get working just as these responses were added. I'm just starting to learn javascript so the scripts you have posted here will be a good place for me to start.

Reply With Quote
  #5  
Old October 23rd, 2009, 05:13 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 48th Plane (28500 - 28999 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 28,838 Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 21st Grade (Above 100000 Reputation Level)  Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2Folding Points: 549372 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 3 Months 2 Weeks 1 Day 14 h 30 m 10 sec
Reputation Power: 2389
Quote:
Originally Posted by rsdesign
Many thanks for these responses, I managed to find some good but admittedly more elaborate javascript with a couple of effect functions that I was able to get working just as these responses were added. I'm just starting to learn javascript so the scripts you have posted here will be a good place for me to start.
cheers, thanks for sharing this with us and glad you achieved your goal.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > JavaScript - Need help with javascript gallery thumbs


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek