posted on:January 23, 2008
Style Your Image Links
Mouse over behaviors have a certain significance when we’re talking about usability. Letting users know that particular section of our website is meant to be clicked on is best achieved through mouse over effect. Those “clickable” sections certainly include content images. But what can you do with image mouseovers? Add a different border? This script will certainly help you to do a bit more than that…
Take a look at the Demo
| Download Image Link
What is it?
Image Link is a script that enables you to apply additional styling to your image links. It has two states: default and mouseover states, so you can use it i.e.on your gallery thumbnails to display a little zoom icon when thumbnail is rolled over or to place a "click here" message at the bottom of your image…
Why is this script different (better) than similar scripts?
This is totally unobtrusive piece of JavaScript. It doesn’t demand any interventions in html except for class naming of particular images that you wish to style. If you want to use the same style for all of your image links you don’t even have to assign classes. The script will automatically apply styles to all images inside anchor tags.
How does it work?
Script goes through the source code and locates images inside anchor tags – image links. It creates a span element that is placed above the image. Script then assigns css class to that span based on your preferences.
So, Image Link script basically takes your markup that should look like this:
<a href="/somelink"><img src="image.jpg" alt="My Image" /></a>
turns it into this:
<a href="/somelink"><img src="image.jpg" alt="My Image" /><span></span></a>
and gives you an "image cover" to work with and style it as you wish.
Parameters and variations
There are 2 variations of this script to suit your preferences. One is single style variation and other is multistyle.
Single style is easier to set up and perfect for those who wants one style throughout the site. It has 3 variables that you can configure in the config section of the JavaScript file:
imageClass – a string that you use to provide a class name for the images you want to get "styled". If you want Image Link script applied to all images inside anchors, leave this string blank.
defaultClass – a string that you use to provide a class name that defines how image covering span is styled by default
overClass – a string that you use to provide a class name that defines how image covering span is styled when rolled over
Multistyle version of the Image Link looks a bit more complicated but it gives you a possibility to use multiple styles on different images. Config section consists of JavaScript array where each item is an array of 3 subitems. Those 3 subitems are exaclty the same ones as in single style version: a image css class (used to locate the image), default css class for image covering span and css class used for image covering span when rolled over.
How to apply it to your own site?
Download the zip containing sample files, unpack and place folders in the root of your site and insert this line of code to your head tag:
<script type="text/javascript" src="imagelink/imagelink.js"></script>
In your css file you should create styles that you will use with Image Link script. Create your own or use some of the styles from the demo, it’s up to you. Just make sure that you insert correct css class names in the config section of the JavaScript file.
For advanced developers, this can be a starting point with many possibilities. Some of them will be explained in another article when I release Image Link v2.0 so stay tuned.
Note
For best results in all browsers, you should set position:relative on containing element. So, if you have text with images placed inside a div id=content, put position:relative to that div.
Enjoyed the article?
Then don't miss our next one! Subscribe to our RSS feed or share it with your friends.
Share on FacebookTweet thisDeliciousStumbleUpon RedditSubscribe
Comments (52 Comments)
Sorry, the comment form is closed at this time.
Lim Chee Aun
January 24, 2008
Jermayn Parker
January 24, 2008
Jermayn Parker
January 24, 2008
cssglobe
January 24, 2008
TrevorGerzen
January 24, 2008
Abraham Estrada
January 25, 2008
andiszek
January 25, 2008
cssglobe
January 25, 2008
An Jay
January 25, 2008
andiszek
January 25, 2008
cssglobe
January 25, 2008
andiszek
January 25, 2008
Peter
January 26, 2008
capz
January 26, 2008
Ep
January 26, 2008
Trainingstagebuch
January 26, 2008
BillyG
January 26, 2008
cssglobe
January 26, 2008
Ozh
January 26, 2008
cssglobe
January 26, 2008
Marko
January 27, 2008
Sauravh
January 28, 2008
Tartak WWW
January 28, 2008
Kurzmelder
January 28, 2008
MrBelm
January 30, 2008
cssglobe
January 30, 2008
MrBelm
January 30, 2008
rasc
January 31, 2008
Steph
January 31, 2008
tetblue
February 14, 2008
adrian
February 18, 2008
jf
February 27, 2008
Süleyman Sönmez
March 7, 2008
Ayush
April 4, 2008
coco
April 11, 2008
MyDesign.com.ar
May 6, 2008
moyo
May 22, 2008
Manel
June 4, 2008
Dinesh Kumar
July 16, 2008
Smithveg
July 24, 2008
Anthony
July 24, 2008
zel
August 4, 2008
Timo
August 13, 2008
Risket
September 4, 2008
Blackwings
September 11, 2008
fabio
October 8, 2008
Anders
October 15, 2008
Lars
December 21, 2008
hakan
December 28, 2008
MatÃas
April 17, 2009
Burt Abreu
May 27, 2009
ANTHONY
June 29, 2009