Web Services

Thickbox Tutorial

What is ThickBox?

ThickBox is a webpage User Interface (UI) dialog box feature written in JavaScript on top of the jQuery library. Its function is to show a single image, multiple images, inline content, iframed content, or content served through AJAX in a hybrid modal.

ThickBox Features

  • The ThickBox JavaScript code and CSS file only add an additional 12k on top of the jQuery code. Together, the compressed jQuery code and ThickBox only total 51k.
  • ThickBox will resize images that are bigger than the browser window.
  • ThickBox offers versatility (images, iframed content, inline content, and AJAX content).
  • ThickBox will hide form elements in Windows IE 6.
  • ThickBox will remain centered in the window even when the user scrolls the page or changes the size of the browser window. Clicking an image, the overlay, or close link will remove ThickBox.
  • The ThickBox creator has decided that animation should be tailored by individual authors. So yeah, ThickBox no longer animates. Is this a feature? Well, some might say it is.

Top

ThickBox Setup

There are four files required for ThickBox to work correctly:

Save the file to the appropriate place. In our case, we will save the JavaScript files to the "_scripts" folder, "thickbox.css" to the "_styles" folder, and "loadingAnimation.gif" to the "images" folder fot the site we are working on.

Before you can implement ThickBox make sure the page that invokes ThickBox has a valid DTD. This is required for ThickBox to look and function correctly.

Top

Implementing ThickBox

  1. You will need to include the JavaScript and CSS file that you just downloaded in order for ThickBox to work correctly:
    <script type="text/javascript" src="$5518"></script>
    <script type="text/javascript" src="$5519"></script>
  2. Include the ThickBox CSS file:
    <link rel="stylesheet" href="$5511" type="text/css" media="screen" />
  3. View the examples below to learn the different ways to use ThickBox.

Top

Examples

Single Image

Demo

Sunset

Instructions

  • Create a link element (<a href>)
  • Give the link a class attribute with a value of thickbox (class="thickbox")
  • Provide a path in the href attribute to an image file (.jpg .jpeg .png .gif .bmp

HTML Code

<a href="/web/images/sunset.jpg" title="Sunset" class="thickbox"><img src="/web/images/sunset.jpg" alt="Sunset Image "/></a>

 

Top

Gallery Images

Demo

plant plant2 plant plant

 

Instructions

  • Create a link element (<a href>)
  • Give the link a class attribute with a value of "thickbox" (class="thickbox")
  • Provide a path in the href attribute to an image file (.jpg .jpeg .png .gif .bmp)
  • Give each link element the same rel element and value. (Example: rel="gallery-plants")

HTML Code

td<a href="/web/images/plant1.jpg" title="Plant 1" class="thickbox" rel="gallery-plants"><img src="/web/images/plant1.jpg" alt="plant" width="75" height="56" border="0" /></a>

<a href="/web/images/plant2.jpg" title="Plant 2" class="thickbox" rel="gallery-plants"><img src="/web/images/plant2.jpg" alt="plant2" width="75" height="56" border="0" /></a>

<a href="/web./images/plant3.jpg" title="Plant 3" class="thickbox" rel="gallery-plants"><img src="/web/images/plant3.jpg" alt="plant" width="75" height="56" border="0" /></a>

<a href="/web/images/plant4.jpg" title="Plant 4" class="thickbox" rel="gallery-plants"><img src="/web/images/plant4.jpg" alt="plant" width="75" height="56" border="0" /></a>

 

Top

Inline Content

Demo

Show the three paragraphs below in a ThickBox.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.

Instructions

  • Create a link element (<a href>)
  • Give the link a class attribute with a value of thickbox (class="thickbox")
  • In the href attribute of the link add the following anchor: #TB_inline
  • In the href attribute after the #TB_inline add the following query string on to the anchor:
    ?height=300&width=300&inlineId=myOnPageContent

HTML Code

<a href="#TB_inline?height=300&width=300&inlineId=myOnPageContent" title="add a caption to title attribute / or leave blank" class="thickbox">Show</a>

 

Top

IFramed Content

Demo

Yahoo

Google

Instructions

  • Create a link element (<a href>)
  • Give the link a class attribute with a value of thickbox (class="thickbox")
  • In the href attribute of the link provide the URL you would like to display in a ThickBox
  • In the href attribute, after the URL, add the following query on to the end of the
    URL:?TB_iframe=true&height=400&width=600
  • Change the values of height and width in the query accordingly

HTML Code

<a href="$1845?TB_iframe=true&height=400&width=600" title="yahoo.com" class="thickbox">yahoo</a>


<a href="$3064?TB_iframe=true&height=400&width=600" title="google.com" class="thickbox">google</a>

 

Top

AJAX Content

Instructions

  • Create a link element (<a href>)
  • Give the link a class attribute with a value of thickbox (class="thickbox")
  • Provide a path in the href to the file (.html .htm .cfm .php .asp .aspx .jsp .jst .rb .txt) on the server. (href="ajaxLogin.htm")
  • In the href attribute, after the URL path to the file, add the following query on to the end of the URL:
    ?height=300&width=300
  • Change the values of height and width in the query accordingly

HTML Code

<a href="ajaxOverFlow.htm?height=300&width=300" title="add a caption to title attribute / or leave blank" class="thickbox">Scrolling content</a>  

<a href="ajax.PHP?height=220&width=400" class="thickbox" title="add a caption to title attribute / or leave blank">No-scroll content</a>  

<a href="ajaxLogin.htm?height=100&width=250" class="thickbox" title="Please Sign In">login</a>

 

Top

That's It!

Enjoy!

 

" src="http://seaborn.csuchico.edu:8081/servlet/images/cmcodeasp.gif" oncontrolselect="window.event.returnValue = false;">