Home arrow JavaScript arrow Page 2 - Using JavaScript Click Interceptions in an Image Gallery
JAVASCRIPT

Using JavaScript Click Interceptions in an Image Gallery


If you’re a web developer with an intermediate level of experience building JavaScript applications, then you may have already used click interceptions in one form or another. Basically, as its name would suggest, this client-side method consists of “catching” a mouse click that occurs on a selected element of a web page to modify its default behavior. In this second part of a four-part series, you'll learn how to use click interceptions in an image gallery.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 5
November 12, 2008
TABLE OF CONTENTS:
  1. · Using JavaScript Click Interceptions in an Image Gallery
  2. · Building the basic structure of an image gallery
  3. · Using click interception to modify existing behavior
  4. · Listing the full source code of the improved image gallery

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using JavaScript Click Interceptions in an Image Gallery - Building the basic structure of an image gallery
(Page 2 of 4 )

Before I get my hands dirty coding any practical example, let me explain briefly how I plan to build this sample image gallery, which will be improved later on by means of click interceptions. First, the gallery in question will be comprised of a list of regular HTML links, which, when clicked on, will display in a different window a predefined image associated with the text included in each link. Still with me?

Then, once this basic image gallery has been constructed, I'm going to use a few click interceptions to change the default behavior of the aforementioned links, and consequently, show the images on the same web page, instead of using a distinct one.

But, as I said before, this process will be performed later on. So pay close attention to the definition of the following (X)HTML file, which is responsible for building the pertinent list of image links: 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Example on building an image gallery using click interception</title>

<style type="text/css">

body{

padding: 0;

margin: 0;

background: #fff;

}

h1{

font: bold 18pt Arial, Helvetica, sans-serif;

color: #000;

}

a:link,a:visited{

font: normal 10pt Arial, Helvetica, sans-serif;

color: #00f;

}

a:hover{

color: #f90;

}

#linkcontainer{

width: 300px;

padding: 5px;

background: #eee;

}

#imgcontainer{

width: 300px;

text-align: center;

}

</style>

</head>

<body>

<h1>Example on building an image gallery using click interception</h1>

<div id="linkcontainer">

<ul>

<li><a href="sampleimagea.gif" title="First sample image goes here">View first image</a></li>

<li><a href="sampleimageb.gif" title="Second sample image goes here">View second image</a></li>

<li><a href="sampleimagec.gif" title="Third sample image goes here">View third image</a></li>

</ul>

</div>

<div id="imgcontainer"></div>

</body>

</html>


As you can see, the above (X)HTML file is quite simple to grasp, since all that it does is display a list of three links, which, when clicked on, will show a specific image in a different window. In this case, the sample images that I'm going to use here are called "sampleimagea.gif", "sampleimageb.gif" and "sampleimagec.gif" respectively. If you're curious about how they look, you can take a look at them below:





So far, everything looks good. If you test the previous (X)HTML file on your own browser, in conjunction with the three images shown above, then you'll end up seeing a list of descriptive links, which, when clicked, will display the associated image in a different window.

But what if I want the images in question to be shown in the same web page? Here's where click interceptions come in. It's possible to develop a small JavaScript application that changes the default behavior of each link included in the previous image gallery to display all the images within a predefined container of the same web document.

Sounds pretty interesting, doesn't it? However, to see how this process will be performed, you'll have to click on the link below and keep up reading.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials