uk gay personals

kansas city escort service

com women

get laid tonight

black booty com

best free dating

yahoopersonals co

housewife lesbian

swinger fun

http www adultmatchmaker com

iraq hot women

dc swinger

large mature women

personals chat room

hotteens com

match makers

german men dating

walking holidays singles

1 personals

gps friend finder

sex seeking

winesingles

gay personals uk

dating services comparison

best free online dating

sex gratui

sex best sites

michigan singles events

hotmail personals

lesbian uk chat

dating online personals

jewish singles events nyc

chatting live with girls

cheating wifes pictures

rich men single

mail order brides filipina

rencontre couple

dating and chating sites

singles swinger

boston online dating

chat escort

meet japanese singles

single board computer linux

kerala sex web

callgirls com

dating arab women

find a lover

detroit personals

lexington singles line

get laid online

iwantu dating

singles new brunswick

sexual encounters

tru com

www scorts

arabic singles

wife affair

search sex

sex pub

fairfield singles

links adult

directdating co uk

sex web chat

cam bedroom

denver single women

everlast singles

dating danmark

teenagers dating online

adultfinder password

christian singles nz

video dating software

pictures older women

dating internet online

sex chat password

clubs for singles

true dating review

woman sex work

single latin women

free personal sites

asian single

www gay chat com

personals miami

asian men dating white women

hilo dating

dating in usa

datingsite in usa

personals singapore

free date web site

plano singles

adults only dvds

singles over 40

swinger quest

sex serch com

one gay date

single board computer uk

resources for single moms

guys get laid

child free singles

date a girl

having sex on cam

Using Javascript to Set a Slide Background

Posted by jonathan on February 28, 2006

One of the problems of making a good image display page is the problem that some images come in portrait format, and some come in landscape. There are several ways to set up appropriately formatted thumbnail backgrounds including:

  • pick each thumbnail background manually, or
  • use only one format so a consistent background can be applied, or
  • write some code! (This is what we’ll be doing!)

In this blog entry I’ll use the slide templates from project two into the book ‘More Eric Meyer on CSS’ (by Eric Meyer). You can get the files here. Also, the book is highly recommended.

As you can see, Eric has done a really nice job of creating a great set of formatting that really does look like slides on a lightbox. However, there is a big problem. We need to know beforehand about the shape, portrait or landscape of each slide.

Here’s the (unwrapped) css formatting magic that Eric uses:

body {background: #EED; margin: 1em;}
div#footer {clear: both; padding-top: 3em;
font: 85% Verdana, sans-serif;}
div.pic {float: left; height: 130px; width: 130px;
padding: 15px; margin: 5px 3px;
background: url(frame-ls.gif) center no-repeat;}
div.pt {background-image: url(frame-pt.gif);}
div.pic img {border: 1px solid; border-color: #444 #AAA #AAA #444;}
div.ls img {height: 96px; width: 128px; margin: 16px 0;}
div.pt img {height: 128px; width: 96px; margin: 0 16px;}
div.pic ul {display: none;}

As you can see, we have a div.ls and a div.ps to be used for landscape and portrait images respectively.

This code does great formatting, but has the big problem that you need to set up each thumbnail individually. This is a problem when you are dealing with large numbers of images, or when generating sets of a few random images from a large list of images.

I’m going to take the approach of shimming in some Javascript to looks at the images and pick the appropriate div formatting dynamically as the page loads.

Lets take a look at the required Javascript.

// ::slide_frame()
// Use the correct slide frame for loaded images
// This gets called when the body is loaded.

function slide_frame() {
// Get slide divs in document
slides = document.getElementsByName( “slide” );

// Iterate over all the slides
count = slides.length;
for( i=0 ; i

// Get child img, we need this to handle any whitespace
// in the div.
for( node=0 ; length > node ; ++node ) {
if( slides[i].childNodes[node].className == ‘flh’ ) {
pic = slides[i].childNodes[node];
break;
}
}

// Set offset of image within slide (In this case I hardcoded to the slide size)
w = (160 – pic.width) / 2;
h = (160 – pic.height)/ 2;
pic.style.margin= h + “px ” + w + “px ” + h + “px ” + w + “px “;
pic.style.border=”1px dotted black”;

// Check aspect ratio of thumbnail
if( pic.width > pic.height ) {

// Give it a landscape slide background
slides[i].style.background=”url(‘frame-ls.gif’)”;
}
}
}
The Javascript should be pretty clear as all it does is switch the background property of the slide div.

Now all we need to do is construct some slides to display, and attach the slide_frame() code to the onLoad event of the document body.

Click here for an example of this in action.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

Comments