Style Sheets
  Home arrow Style Sheets arrow Page 3 - Dynamic Galleries with DOM and CSS
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Dynamic Galleries with DOM and CSS
By: Chris Heilmann
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 22
    2005-01-31

    Table of Contents:
  • Dynamic Galleries with DOM and CSS
  • Basic Functionality of a Thumbnail Gallery
  • Old School Dynamic Galleries
  • Sketching our Gallery
  • The Javascript
  • The Stylesheet
  • A Sequential Gallery
  • Other options

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Dynamic Galleries with DOM and CSS - Old School Dynamic Galleries


    (Page 3 of 8 )

     

    When Javascript became more common, many developers with a lot of time and a lot of enthusiasm on their hands came up with hundreds of “DHTML galleries,” at times appallingly one-browser-centric and bloated ones. Nearly all of them used pop-up windows to display the images, and relied on a lot of inline event calls with a lot of parameters: 

    HTML: 

    <a href="javascript:showpic('images/archway.jpg',300,300) ">

    <img src="images/tn_archway.jpg" alt="Archway with natural green roof" />

    </a>

     

    JavaScript:

     

    function showpic(pic,x,y)

    {

         newwin=window.open(pic,'newwin','width='+x+',height='+y+'toolbar=no')

         newwin.moveTo(screen.width/2-x/2,200);

    }

     

    This practice leads to completely dead galleries in browsers without JavaScript. A better way is to always ensure there is a link to the image and JavaScript that adds the pop-up functionality on top of that.

     

    <a href="images/archway.jpg"

    onclick="showpic('images/archway.jpg',300,300);return false;">

    <img src="images/tn_archway.jpg" alt="Archway with natural green roof" />

    </a>

     

    These pop-up window examples still did not allow for a link back or extra information to be displayed. Seeing that as a problem, developers started writing out HTML dynamically:

     

    HTML:

     

    <a href="images/archway.jpg"

    onclick="showpic('images/archway.jpg','An archway in Santorini',300,300);return false;">

    <img src="images/tn_archway.jpg" alt="Archway with natural green roof" /></a>

     

    Javascript: 

    function showpic(pic,message,x,y)

    {

        newwin=window.open(pic,'newwin','width='+x+',height='+y+'toolbar=no')

        newwin.document.open();

        newwin.document.write('<html><head><title>Big picture</title></head>');

        newwin.document.write('<body bgcolor="#0000000">');

        newwin.document.write('<a style="float:right;font-family:arial;color:#369;"

        href="javascript:window.close()">Close</a>');

        newwin.document.write('<h1

        style="color:#fff;font-size:12px;font-family:arial;">'+message+'</h1>');

        newwin.document.write('<img src="'+pic+'" alt="'+message+'">');

        newwin.document.write('</body></html>');

        newwin.moveTo(screen.width/2-x/2,200);

    }

     

    There was no end to their creativity: sliding windows, fading in images, galleries with templates using the window location to read image location and message, and lots more. All of them had several drawbacks: 

    • Bad maintainability - the idea of a dynamic gallery is that it enhances the basic HTML without any extra link event calls with a lot of parameters.

    • Bad Accessibility - they relied on Javascript for the functionality.

    • Bad performance – Instead of one browser, the machine needed to start a new window every time the user clicked a thumbnail.

    • Pop-ups - These might be blocked by a lot of users nowadays. 

    Let’s try to keep things as simple as possible, and not listen to the "feature creature" on our shoulders telling us to add more, more and some more later. 

    More Style Sheets Articles
    More By Chris Heilmann


       ·  Hi Chris, Nice article! I liked a lot the use of the DOM approach....
       · I liked the article a lot but a copy of the source code and style sheet would be...
       · [url]http://icant.co.uk/articles/dyngallery/dyngallery.zip[/url], however without...
       · Thanks for the link to the zip file.The source files just lets me see how it all...
       · Hi! Great article you have there! Honestly, it's my first time to see this kind of...
       · Guess I'm not the "Anonymous Loozah" :) but I have a comment on this article and the...
       · And it works perfectly here... Netscape 4.x should neither get a stylesheet nor...
       · This is a great article, but it is a pity, that the example doesnt work well in my...
       · The gallery works perfect on my firefox, on 3 different computers. Can you please...
       · It seems tha href is not removed corectly, because it starts a function but...
       · I forget to say, that the problem on my firefox could be with tab browser extension,...
       · Script works great on IE, but I can't adjust the positioning of the big pic in...
       · You got a URL where we can see the problem?
       · Here's the URL (temporarily,...
       · 1) Your pages are in quirksmode2) Your HTML is tagsoup :)...
       · Thanks for your response. The page is now fixed and validating with a HTML 4.01...
       · I love this article as it produces exactly what I am looking for. The only thing is...
       · This script was the best way to do a gallery that I could find - others seemed to...
       · Please fix the floating ads on the right side of the screen. They are floating over...
       · hiya,great script, looks really good - only problem is that when I run in IE7...
     

    STYLE SHEETS ARTICLES

    - Image Replacement CSS Techniques
    - Using BlueTrip`s Success, Notice and Error C...
    - More Uses for the Thin and Caps CSS Classes ...
    - Styling Definition Lists with the BlueTrip C...
    - Styling Unordered and Ordered HTML Lists wit...
    - Using the BlueTrip CSS Framework`s Thin and ...
    - Adding Borders to Web Page Columns with Blue...
    - Introducing the BlueTrip CSS Framework
    - Using a Background Grid to Assist Web Page L...
    - Extending the Rule Of Thirds for Web Page La...
    - A Two-Column Web Page Layout Based on the Ru...
    - Using the Rule Of Thirds for Web Page Layout
    - Swapping Columns Using the Divine Ratio for ...
    - Using the Golden Ratio in Liquid Web Page De...
    - Fundamental Design Principles for Web Page L...







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