Garagedoor effect using Javascript

13

You might have noticed the menu at the top right corner of the website. That’s something what I like to call the GarageDoor effect.

Creating one has now been made easy! This tutorial explains everything you need to know on how to create the same effect yourself.

Garagedoor effect using Javascript

Download
Garage Door Effect zip-archive
Example
Open the Garage Door example

An example of the GarageDoor effect in work is found here: http://www.gayadesign.com/scripts/garagedoor/
Download the following archive containing everything you need: http://www.gayadesign.com/scripts/garagedoor/garagedoor.zip

Unzip the contents of the archive and upload the contents to your server, the set folders can be adjusted to your needs.

First we need to make the script ans style of the GarageDoor work. To make that happen, you’ll need Scriptaculous. This library enables interface effects, so you don’t have to create it yourself. So grab Scriptaculous and upload it to your server. Make sure you also upload the prototype.js file (in the lib folder).

Add the following code in the <head> tag of your page:

<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/scriptaculous.js" type="text/javascript"></script>

<script src="js/garagedoor.js" type="text/javascript"></script>
<link href='css/garagedoor.css' rel='stylesheet' type='text/css' />

This will load the scripts and styles needed for the GarageDoor to work. Adjust the paths where needed.

The next thing you want to do is to create the HTML layout for the garagedoors. The following code shows the structure you need to create for your document:

<div class='garagedoor' id='garagedoor'>
    <div title='linktofile' class='item'>
        <div class='underlay'>
            Caption text
        </div>
        <img src='uritooverlayimage' class='overlay' />
        <div class='mouse'><img src='images/nothing.gif' />&nbsp;</div>
    </div>
    <div title='linktofile' class='item'>
        <div class='underlay'>
            Caption text
        </div>
        <img src='uritooverlayimage' class='overlay' />
        <div class='mouse'><img src='images/nothing.gif' />&nbsp;</div>
    </div>
</div>

This contains two items that will be the garagedoor. The keywords linktofile and uritooverlayimage have to be adjusted in order to make it work. Linktofile is the URLĀ of the page the button has to link to, might be confusing because it’s not an a tag, but Javascript fixes it for you.

The items have a default size of: 100px width and 80px height. Create overlay images according to these dimensions. In order to change the size, take a look in the garagedoor.css file and adjust the width and height of several elements.

All there is left to do is call the GarageDoor to enable the effect!

<script>
    GarageDoor.scrollY = -55;
    GarageDoor.scrollX = 0;
    GarageDoor.setBindings('garagedoor');
</script>

The first line in the <script> tag sets the amount of scrolling the overlay has to do when the cursor is floating over an item. In this example the overlay has to go 55 up, which means move -55px on the Y-axis.
You can also make it scroll horizontal.

Give the id of the garagedoor container to the setBindings method and the GarageDoor effect will be initialized! Be sure to make the call after creating the html.

You are now set to use the GarageDoor Effect. Good luck!

Articles like this one

If you liked this article you can add this post to:


 

12 Comments

  1. Sieb said: December 30, 2008 at 1:43 pm | Permalink

    Yeah that’s our door!


  2. Gaya said: January 1, 2009 at 6:44 pm | Permalink

    It sure is =D


  3. Patrick said: January 18, 2009 at 1:19 am | Permalink

    Tried this but it only seems to work with the nothing.gif you’ve included in your download. Even editting the nothing.gif breaks it..


  4. Gaya said: January 18, 2009 at 2:05 pm | Permalink

    Yeah, the nothing.gif is a fix for IE6. If it would have worked like in Mozilla, then there wouldn’t be such an ungly fix.


  5. Patrick said: January 18, 2009 at 2:46 pm | Permalink

    So how to make it work with your own icons then?


  6. Gaya said: January 18, 2009 at 2:50 pm | Permalink

    uritooverlayimage need to be replaced with yours =) (eg. /images/icons/icon1.png)


  7. Patrick said: January 18, 2009 at 2:51 pm | Permalink

    Never mind, I was being stupid.. the SRC replacing with your own..

    Anyway, looks great! And love your new design


  8. Gaya said: January 18, 2009 at 2:52 pm | Permalink

    Cool thnx =D have fun!


  9. Patrick said: January 22, 2009 at 3:45 pm | Permalink

    Hey Gaya, is it possible to make this W3C XHTML valid?


  10. Gaya said: January 22, 2009 at 10:54 pm | Permalink

    Was thinking about that too, will make it valid later. Seems block elements aren’t supposed to be in link tags. Will fix, will fix


  11. Patrick said: January 22, 2009 at 11:28 pm | Permalink

    K, thanks, could you send me an email when you’ve done so?


  12. Gaya said: January 24, 2009 at 4:54 pm | Permalink

    This script is now xhtml valid


Leave a Comment

Your email is never shared. Get your own avatar with gravatar! Required fields are marked *

*

*



One Trackback