jQuery convertion: Garagedoor effect using Javascript

67

Today I finally found the courage to go and try jQuery. After getting some people say: “You should use jQuery instead of scriptaculous.” I began thinking. What is the reason I choose script.aculo.us again? Must have been something I read in that time.
Anyway, today I found the time to look at jQuery a bit and thought: Let’s convert my very first posted script to jQuery!

After 5 minutes of reading about selectors in jQuery and 15 minutes of coding it was born. I am super amazed by the results! About 40%/50% less code and about 200% less time needed to write the script. I bet that in the future 400% less time is reachable!

For all the jQuery lovers: Here is the Garage Door effect. Now in jQuery!

jquerygarage

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

Since this article is a redo of Garagedoor effect using Javascript I’ll just make it so that it fits jQuery.

An example of the GarageDoor effect in work is found here: http://www.gayadesign.com/scripts/jquerygaragedoor/

Download the following archive containing everything you need: http://www.gayadesign.com/scripts/jquerygaragedoor/jquerygarage.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 jQuery. This library enables interface effects, so you don’t have to create it yourself. So grab jQuery and upload it to your server.

Add the following code in the tag of your page:

<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>

<script src="js/garagedoorjQuery.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>

his 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.

Hope you liked this jQuery version of the Garage Door. No more prototype conflicts!

Stay tuned for more jQuery convertions!

Articles like this one

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


 

25 Comments

  1. Louis Gubitosi said: April 8, 2009 at 7:45 pm | Permalink

    dude, keep up the good work! I’m sure I’ll be using these tut very soon. thanks again…


  2. Gaya said: April 8, 2009 at 7:50 pm | Permalink

    thanks Louis for commenting and RTing my tweets =D


  3. Drew said: April 8, 2009 at 8:01 pm | Permalink

    This is awesome Gaya, it’s really nice to see you getting into jQuery as it is my Javascript library of choice. You should consider submitting some of these to NETTUTS, the quality is superb.


  4. Gaya said: April 8, 2009 at 8:18 pm | Permalink

    @Drew
    Thanks Drew! I was thinking about submitting something to NETTUTS. Already pitched an idea to them. I think my next Javascript / jQuery adventure will be for NETTUTS.

    Also: Dev-tips is now in the partners list. Thanks again Drew.


  5. Janko said: April 8, 2009 at 9:33 pm | Permalink

    Awesome effect, good to see you’ve done it with jQuery easily!


  6. Gaya said: April 8, 2009 at 9:49 pm | Permalink

    @Janko:
    Yeah! jQuery amazed me! This will save me so much time!


  7. Marco said: April 8, 2009 at 10:01 pm | Permalink

    Finally, you see the “light of jQuery”. Took you a while, but I’m glad you made it.

    Anyway, still pretty cool to see this neat effect, now using jQuery! Well done Gaya, keep up the good work :) .

    Ps. Load jQuery from Google, will save you bandwidth and hosting multiple jQuery files :) .


  8. Gaya said: April 8, 2009 at 10:04 pm | Permalink

    @Marco
    Thanks for being part of my enlightenment Marco. I hope this will bring more interesting developers to my site =)

    Will load from google if I am implementing jQuery on GayaDesign. Will save me time, and the user!


  9. Pim said: April 9, 2009 at 8:50 am | Permalink

    “Hate to say I told you so” ;) Keep up the good work Gaya. Will save me some frustrations as well ;)


  10. Matěj Grabovský said: April 9, 2009 at 6:58 pm | Permalink

    Awesome, another jQuery victim, muhahahaha, anyway congratulations on discovering the power of jQuery and making such a nice tutorial.


  11. Matěj Grabovský said: April 9, 2009 at 7:00 pm | Permalink

    Sorry for double post but a suggestion: how about a variable controlling the scrolling speed?


  12. Gaya said: April 9, 2009 at 8:18 pm | Permalink

    Great idea Matěj! Could be implemented with ease. But note that the garage door opens faster than closes. Anyway, thanks for the comment!


  13. Pablo said: May 9, 2009 at 6:10 am | Permalink

    Great effect. Can I suggest that you add your example page and images to the package. It makes it easier to download, get it working locally and then modify.


  14. Nitin Sawant said: May 16, 2009 at 3:36 pm | Permalink

    gr8!! effect,

    your site design is also good,

    regards,
    Nitin Sawant


  15. Gaya said: May 19, 2009 at 10:49 am | Permalink

    Thanks for the comment Nitin :)


  16. GadenStar said: July 17, 2009 at 2:59 am | Permalink

    very cool!!


  17. Jose said: July 29, 2009 at 7:38 am | Permalink

    great stuff, bro! thanks for sharing!
    your site rocks :) the 3d stuff is nicely done.


  18. Sofian said: October 28, 2009 at 12:49 am | Permalink

    Awesome.. thank you Gaya..
    (in my country Indonesia : Gaya means Style)


  19. Gaya said: October 28, 2009 at 9:10 am | Permalink

    @Sofian: hah, thanks dude. I’ve heard that one before. Funny thing that I’m half Indonesian


  20. Techie Talks said: November 28, 2009 at 10:50 am | Permalink

    Wow! This is such an impressive site. How did you do the header its cool to see.


  21. Jack Starr said: November 30, 2009 at 6:21 am | Permalink

    nice article…maybe, its more wonderful with png image….


  22. wespai said: December 31, 2009 at 3:54 am | Permalink

    thx collect it to

    ajax.wespai.com


  23. chicago web design said: April 9, 2010 at 3:50 pm | Permalink

    Good that you finally found jquery and shared it with us.


  24. Martin Holm said: May 6, 2010 at 9:04 pm | Permalink

    Hi you guys

    is it possible to put more than one link underneath each “garage door”? If so, how do i do it?? :)

    hope you have an answer because i am really stuck on this one..


  25. alex said: August 9, 2010 at 9:49 pm | Permalink

    Cheerful menu :)


Leave a Comment

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

*

*



42 Trackbacks

  1. By 清晰博客 » 36个引人注目JQuery导航菜单 on September 17, 2009 at 5:45 pm
  2. By Os 25+… Menus e Plugins em jQuery! | PixelFont on October 22, 2009 at 2:08 pm
  3. By 25 Menus e Plugins para Jquery | Renan Lima on October 23, 2009 at 9:17 pm
  4. By 享受生活 » 36个引人注目JQuery导航菜单 on January 2, 2010 at 11:52 am
  5. By 33 jQuery tutorials to create Navigation Menu on June 2, 2010 at 12:55 pm
  6. By 33 jQuery Menü | SyncapNoktaOrg on June 10, 2010 at 12:09 pm