The Dock - as anyone familiar with a Mac will know - is a set of iconic images that expand when rolled over with the cursor, and usually perform some action when clicked. This plugin mimics that behaviour by transforming a contiguous set of HTML images into an expanding Dock, vertical or horizontal, with or without labels.
Basically, all the Dock does is expand a reduced size image towards its full size when the cursor is on or near it. You can specify a vertical or horizontal orientation for the Dock, and select the direction in which the image should expand and whether to show labels or not. The styling and positioning of the Dock is (almost) entirely down to you.
You can use 2 different images for clarity, one for the minimised 'at rest' state, and one for performing the enlargement to its full size. Alternatively, you can just use the one larger image as long as you are happy with its definition when reduced by the browser.
There is no restriction on the type of image that can be used (gif, jpg, png), but obviously if you are applying any styling to your Dock that makes it stand out against the background (such as a border or background colour), then a transparent GIF or PNG (8-bit for IE6!) may be preferable to an image that displays with an opaque background. The images can be enclosed within links, or not, depending on how you wish to control your navigation or application. The only requirement is that the parent container, probably a DIV, holds only images and/or anchors that enclose an image.
You may need to ensure that the placement of your menu allows for expansion, either horizontally or vertically depending on the assigned alignment. The Dock will extend one or both ends of its major axis as the images are rolled over, as well as enlarging the relevant images themselves, and you want to avoid having it disappear off screen, or under other elements, if you can help it. Unless instructed otherwise (the flow option, added at v1.5), the Dock will always do its best to position itself centrally (along its major axis) within what it thinks is the maximum space required for any expansion.
The Dock uses the document's original HTML, in other words it does not create clones and append them to the end of the document. This means that the container element to which you apply jqDock() is what controls the position of the Dock, and what elements the Dock can appear on top of. Although absolute positioning is used, and several wrapper elements are added below the container element, any other elements in your document may be styled in such a manner as to obscure all or part of the Dock. It is therefore recommended that the container element be placed or positioned with care within your document such that the Dock will not appear underneath any other elements on the page.
jqDock was inspired by, and owes full credit to, Isaac Rocca's "iconDock" plugin - http://icon.cat/software/iconDock/. I have simply re-modelled it, tweaked it, expanded it, and re-packaged it.
<div id='menu'> <img src='image1.gif' alt='image1.png' title='' /> ... <a href='page.html' title=''> <img src='imageN.png' alt='' title='' /></a> ... </div>
A menu contains images, which may or may not be within links - you can mix and match as you wish. You should provide css styling as necessary to position your menu where you want the Dock to appear. You can initially hide it (display:none; or - from v1.5 - visibility:hidden;) if you wish; jqDock will reveal it once initialised. You can set the width and/or height styles on the images - for instances where javascript is disabled? - but you should avoid using the width and height IMG attributes.
Images are always expanded to their full natural width/height, or a fraction thereof, depending on the position of the cursor at the time. You can not control the ultimate dimensions of the expanding image by css, because jqDock overrides it, and if you try using the width/height attributes things won't work as expected.
If an image's 'alt' attribute contains what looks like an image path (ends with a dot-suffix of gif, png or, jp[e]g) then 'src' will be used as the small image and 'alt' as the larger, expanding one.
By default the 'labels' option is off, and jqDock will remove any values for 'title' and 'alt' attributes (after examination), in an attempt to prevent the browser displaying a tooltip when hovering over an image (causes 'fluttering' in some browsers if the cursor is allowed to move over the tooltip). Also, jqDock will remove all text nodes within the menu - this helps to ensure a known and standard presentation of the Dock, and smooth animation.
Important! This plugin requires at least jQuery v1.2.3, because it uses API constructs that only became available in that version. However, I would always recommend that you try to use the latest version, for speed and efficiency.
Link in the jqDock source (full or compressed) after jQuery itself...
Example:<script type='text/javascript' src='jquery-1.2.3.min.js'></script> <script type='text/javascript' src='jquery.jqDock.js'></script>
To convert your HTML into a Dock, simply call the jqDock function in the standard manner...
Example:jQuery(document).ready(function(){
jQuery('#menu').jqDock(Options);
});
jqDock() supports full chaining, noConflict(), and the metadata() plugin.
There are a number of options available, which can be set on per-Dock basis. None of the options are mandatory since they all have defaults.
Example://the most commonly used options are likely to be align, size and labels, closely followed //by fadeIn and inactivity (the other options are probably for the more advanced user) var opts = // horizontal Dock with images expanding downwards in the vertical axis... { align: 'top' // set the maximum minor axis (vertical) image dimension to 48px , size: 48 // add labels.. , labels: true // swap the GIF extension for PNG extension for the larger image... , source: function(i){ return this.src.replace(/gif$/,'png'); } }; $('#menu').jqDock(opts);
In order to support image switching in real time, jqDock() supports a small alternate set of options for use solely on images.
When passed a selection of elements that consists solely of IMG elements that are already part of a jqDock menu, jqDock() will accept 2 options, that effect a change of an image's source path.
Example (strings):$('#menu img').eq(0).jqDock({src:'imageAlpha.gif', altsrc:'imageAlpha.png'});
Example (functions):
var fnChangePath = function(current, type){
//always change altsrc, but only change src if image has a class of 'changeExpanded'...
return type == 'altsrc' || $(this).hasClass('changeExpanded')
? current.replace(/old\.png$/, 'new.png')
: current;
};
$('#menu img').jqDock({src:fnChangePath, altsrc:fnChangePath});
[ You can specify a string for one property and a function for the other, eg 'src' as a string and 'altsrc' as a function. ]
I have provided one example that uses these alternate options - Change image source - on the Examples page.
Important! Even though you may not have initialised the dock with alternate larger images (see the source option above), jqDock will still have 2 separate internal variables: one for the 'at-rest' image path, and one for the expanding image path. This means that if you change one of the paths, it is highly likely (but not inevitable!) that you should be changing both.
As of v1.5, a number of custom events have been introduced, mainly to support the new concept of the Dock being able to "go to sleep". This enables the calling script (if it so desires) to do something with the Dock - like slide it out of view - if it has not been used for a while.
Basically, the Dock will (if instructed to - see the idle option)
go to sleep after a specified period during which the mouse has not
entered the Dock. Technically, it does this by setting a timer on a mouseleave event, cancelling the timer on any mouseenter
or mousemove event (within the Dock). The duration of the timer is set via the idle option, and if the timer fires
then the Dock goes to sleep.
Note that this is totally different to the inactivity option, which is for the absence of mouse movement while
over the dock.
Once the Dock has gone to sleep, the only way to wake it up it is to 'nudge' it. While the Dock is alseep it will not respond to any mouse movement events (enter, leave or move) but it will still respond to clicks.
$('#menu').bind('dockshow', function(){ });
$('#menu').bind('docksleep', function(){ });
$('#menu').bind('dockwake', function(){ });
Each of the above also has a corresponding "on___" option available, which is provided as alternative, synchronous,
function call that precedes notification of the related event:
WARNING : If you return false from an onReady() function you have effectively absolved jqDock of any responsibility for the initial display of the Dock! It is your script that will have to ensure that the Dock is, or becomes, visible and usable, and then 'nudge' the Dock awake.
var doSomething = function(){ $('.jqDock', this).hide(); }
, doSomethingElse = function(){ $('.jqDock', this).show(); };
$('#menu').jqDock({onSleep:doSomething, onWake:doSomethingElse});
$('#menu').trigger('dockidle'); //puts dock to sleep (if not already)
$('#menu').trigger('docknudge'); //wakes dock from sleep, or resets idle timer if not asleep
An alternative to triggering the 'dockidle' or 'docknudge' events is to issue a command string - 'idle' or 'nudge' - directly
to jqDock():
$('#menu').jqDock('idle'); //same as $('#menu').trigger('dockidle')
$('#menu').jqDock('nudge'); //same as $('#menu').trigger('docknudge')
The HTML transform is the same, regardless of the vertical/horizontal orientation of
the Dock, with only slight differences in inline styling between the two. The inline
styles applied by jqDock are not show below, but they do get applied to both the new and
the existing elements, and can vary depending on the browser, the containing page's html,
and the options chosen for jqDock.
As an example, this...
<div id='menu'>
<img class='myFirstOption' src='image1.gif' alt='image1.png' title='Label text' />
...
<a id='mySpecialLink' href='page.html' title='Label text'>
<img src='imageN.png' alt='' title='' />
</a>
...
</div>
...transforms to this...
<div id='menu' class='jqDocked'> <div class='jqDockWrap'> <div class='jqDock' id='jqDock0'> <div class='jqDockMouse0'> <div> <img class='myFirstOption jqDockMouse0' src='image1.gif' alt='image1.png' title='Label text' /> <div class='jqDockLabel jqDockLabelImage'> <div class='jqDockLabelText'> Label text </div> </div> </div> </div> ... <div class='jqDockMouseN'> <div> <a id='mySpecialLink' href='page.html' title='Label text'> <img class='jqDockMouseN' src='imageN.png' alt='' title='' /> <div class='jqDockLabel jqDockLabelLink'> <div class='jqDockLabelText'> Label text </div> </div> </a> </div> </div> ... </div> </div> </div>Grey : Original HTML
Using the jqDocked, jqDock, jqDockLabel and jqDockLabelText1.5 classes, you can apply CSS styles to modify the presentation of the Dock and labels (if enabled). The jqDockWrap1.3 class also enables some positioning (such as centering) that was not possible in earlier versions. For examples, I suggest looking at the later part of the style.css stylesheet used by these pages (Demo CSS) - it is fully commented and, given the number of demo Docks, should provide all the hints you need. There are also a number of single-Dock examples on the Examples page.
The jqDockMouseN classes are used internally by the mouse events handler to determine the menu item (N) being targeted. The jqDock0 id is also used internally, to determine which Dock is being targeted when there are multiple Docks on a page. (Additional Docks would have equivalent ids of jqDock1, jqDock2, etc.)
The Dock's label has an additional class - jqDockLabelLink or jqDockLabelImage - which indicates whether the current menu option is an image within a link, or just an image, respectively. You can use this class to, for example, set the cursor for the label to be the same as the image it relates to.
Please be aware that although jqDock does not remove any original classes or ids, it does apply inline styling to anchors and links in order to ensure that everything works correctly, and these inline styles - such as setting padding, margins and borders to zero - may well override your own CSS rules.
I have tested the demo page and examples in the following browsers:
If anyone can confirm that jqDock works - or doesn't! - in other browsers (and/or operating systems), please let me know.

<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.2.min.js'></script>