7 days of WordPress plugins, themes & templates - for free!* Unlimited asset downloads! Start 7-Day Free Trial
  1. Code
  2. Web Development

Leopard Desktop with jQuery using jqDock

Scroll to top
Read Time: 12 mins

jQuery adds a whole lot of cool functionality to your websites. It can do a range of things, from animation to AJAX. It's usually frowned upon to rely heavily on jQuery to design your sites, but it's fun to go wild every now and then. In this tutorial I'll teach you how to use jQuery to create a completely coded Dashboard, just like Leopard! This can be handy in hiding a whole lot of gadgets or widgets you don't have space for!


This tutorial has a number of components riding upon it. A load of images, a 3rd
party Dock plugin, and the UI.draggable jQuery component, along with, of course,
the jQuery core (v1.2.6). Note: many of the images are probably
copyrighted by their owners. A few dock icons have been taken from their packages
and I've used the Leopard Default Wallpaper. But they're [wallpapers] interchangeable!

Place all of these in a directory. A folder called 'images' (with the images within),
a folder called 'js' with the JavaScript in it.

Plan of Attack

The plan of attack for this tutorial is as follows. On the desktop, there will a
Draggable Window and a Dock. There is another div called #dashboardWrapper that
hides when the jQuery is used. It'll degrade without JS, but not well. The JS plan
of attack I'll explain when we get there.


Aside from the icons being used, I'd also like to point out that this isn't so extensive
as to go all out, getting dynamic widgets etc. You can do that yourselves! This
just provides the basic 'framework' to work with. In fact, when I started writing
this tutorial it started off as a WordPress theme, with the widgets as the widgets
on dashboard. It's still possible! I'll explain how later on.

Step 1 - structure and file includes

Create a file called index.html. This will be the page that looks like Leopard.
You need to rel in all the JavaScript, and the style.css we'll create later. Just
start off with this:

The page then has 3 minimum sections. 2 Divs within the #wrapper (a window and the
actual dashboard), and the dock outside the wrapper. Add these sections in:

Step 2 - Filling in the content

Now we have our 3 basic empty divs. We need to fill them up with the respective
content. Because the Draggable Window is just any old window, you can fill it with
what you want. I created a TextEdit sort of thing, that's just basically a generic
window with text. It'll be styled later! Place this within the '.draggableWindow'.

As said, this is just some filler text for our window. Looks kinda gross, just like
an unstyled page.

Next content filling is the Dashboard. Essentially this can be whatever
You want. Seriously guys, if you take this into your own hands, go nuts. You can
style anything you want within this to look like widgets. As I said, it's not extensive,
it doesn't show actual widgets. I'll explain at the end how to integrate with WordPress.
Place this within #dashboardWrapper:

One of the widgets has some text. This is just to show you can do whatever you want.
Treat the li's as divs! Put whatever! A mini-blog!

Finally, we need the dock. Due to the nature of how the jqDock plugin works, we
can't use a ul for it too easily. Pain, huh? So instead, it's just a few images
next to each other in a div:

See the one with the id of dashboardLaunch? That'll be manipulated with jQuery later

All goes according to plan, your page should have a bunch of text and images. Widgets
and icons, text and headers. It's all junk at the moment.

Step 3 - CSS

The CSS will essentially make the desktop part of the page. It'll include
the background, etc. Let's get down to it. Create a new file called 'style.css',
and place it in the same directory as the other files. Start editing:

Info + Reset

I generally add some info up top of my CSS with my reset so I know what the file's

Desktop interface

Simple. Next up, the body and the window styling:

all relatively easy. The way the h1s are coded with the preceding them uses
the sliding doors technique to make sure that the top bar resizes accordingly. The
ID #smaller was another small modal box I made, just to check it worked. To check
yourself, simply create a new div with the ID of #smaller, and with a h1/#content
div, you can type a short message. Because #smaller has been defined to be a width
of 300px, it'll be just that - a small modal box.

Dashboard styles

Only a few styles are needed for the actual dashboard... Just to make the list item
widgets look pretty, and style the notepad widget!

Dock Reset

Generally most of the Dock's CSS is done in the jQuery Plugin, but for degradable
reasons, and *rough* centering, it still needs a bit of it's own CSS:

And after all that code, (though still rough as guts!) your Leopard Desktop should
look something like this:

Step 4 - jQuery

Woohoo! The fun part! Too all those web lords who despise overuse of JS, I do apologize
but you win some you learn some hm? Now the reason I wanted to write this tutorial
so bad is because it actually made me think in order to make it
- not to say other work doesn't! This I just actually had to think very laterally
to get to the finished product. Gratefully I'll be able to apply that to other projects
- lets hope you do too!

Before I start jQuery I always write an English version of what's needed. As a Rule
of Thumb.

  1. On document load, initiate the dock, initiate draggables and hide any Dashboard
    elements that are still there.
  2. When the Dashboard icon is clicked, activate Dashboard!
  3. When the user clicks back onto the main screen, deactivate the Dashboard.

Fortunately (or unfortunately, depending on how you look at it) it turns out after
figuring it out there's a tad more to it that that. Create a file called 'dashboard.js',
and place it in the JS directory. The JS file reeled in ages ago (up in the HTML
section) is now there! Begin editing!

Always start with a document.ready()!

Plugin definition

Heavily commented, thus self explanatory. Basically launch the dock, initiate the

If you now look at your dock, it zooms (or it should anyway)! Note:
we here at Nettuts probably wont help you too extensively with this piece of technology,
as that's Wizzud's Job!. You should also be able
to drag around the displayed widgets and the dialogue window (only by the h1 along
the top as the handle!).


Hiding Dashboard and initiating the 'Close Zone'

Eh? Close Zone? See if you simply told jQuery to close the Dashboard when the #dashboardWrapper
was clicked in anyway (inclusive of widgets being clicked), then it'd become a pain
because you couldn't actually move around the widgets. So a 'Close Zone' needs to
be created that is a sibling to the widgets (not nestled around) that takes a z-index
of less that the widgets, but more than the desktop. Tricky, huh? The Layering Looks
something like this:


A lot of CSS is used. This is to expand the Dashboard to fit the actual browser
window, and set opacity to 0 so that the animation can fade it in. Hides the entire
element from view too.

Easy peasy!

Position + deactivation of Close Zone

Like #dashboardWrapper, the Close Zone needs to be blown up to fill the window.
The Close Zone is what actually has the semi-trasparent black background, too!

Launch of Dashboard

Now the magic happens! By showing the Dashboard when the #dashboardLaunch is clicked,
the Close Zone is being shown too. This bit of code, however only initiates the
Dashboard. Currently there is no way to escape it except refreshing - Close Zone's
Job is next!


Escaping/Closing the Dashboard

The Close Zone finally gets the spotlight.

Now this has an interesting note. For some reason, jQuery wont do the animation
unless the '.hide' has a time of 1 tenth of a millisecond. Great escapable functionalty!

But what about links...

Apart from the Close Zone, the only other obvious thing that will need to escape
the Dashboard with animation is if a link is clicked. How? Simply the same 'function'
as with the Close Zone.

And that's it! Your dashboard.js should look something like
this js file

Integration into WordPress

As promised, a simple push in the right direction as to how to use this With WordPress.
Fundamentally, all code is eventually HTML and JavaScript when it gets to the browser
end, right? No PHP, no ASP.NET, just maybe some XML too. This principle is essential
to understand, as it means you can apply code to any medium, provided
it's got the same IDs and classes.

Consider the '#content' div of your WordPress blog, given a class of 'draggableWindow.
Give it a h1 at the top, and hey presto! Windowed Post Content. The sidebar, given
an ID (or change it within the JS code) of '#dashboardWrapper', it will automatically
hide until called. That means that all your li widgets for archives and categories
and everything are now seperate widgets.

Even dynamic sidebars have lis with specific classes, allowing them to be styled
like real widgets! The Dock, I'd say is the only thing that would actually need
be added. Not to worry! Due to it's positioning, it's only a div with a bunch of
images in it.

If you want your other Dock icons to link places, An inline a tag wont break anything!
The Static HTML that is spat out by WordPress (or any web technology, really) is
applicable to any CSS or JS created, provided the IDs and Classes are aligned.

Wrap up

OK, put the frowny No-Extensive-JS-Usage Grandaddys at rest, and do your best not
to use jQuery to this extent. This tutorial was just to show how much fun the animation
can really be, and how simple it is to create effects. In fact, if anybody has seen
any effects I'll willingly wait till 5 have been proposed and write an article on
how to do each!

  • Subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.

Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.