Interesting jQuery effect

You know I am trying to use Gallery theme for triqui.com

Yesterday I played a bit with the theme and I completely screwed everything… something like “how to destroy a complex theme in a matter of minutes”.

Then I decided to code something similar by myself. That’s the only way I know to custom everything whenever I want.

One of the best features of Gallery theme is the slider effect, so I played a bit with jQuery until I achieved something similar.

I have to say I tried to make it with Scriptaculous but for these simple effects nothing beats jQuery in my opinion.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
<html>
 
<head>
     <script type="text/javascript" src="jquery.js"></script>
     <script>
          $(document).ready(function(){
               $("#text").stop().fadeTo("slow",0);
               $("#container").mouseover(function(){
                    $("#block").stop().animate({"marginTop": "-30px"}, "fast","linear",function(){$("#text").stop().fadeTo("slow",1);});
               });
               $("#container").mouseout(function(){
                    $("#text").stop().fadeTo("slow",0);
                    $("#block").stop().animate({"marginTop": "0px"}, "fast");
               });
          });
     </script>
     <style type="text/css"> 
     #container{
          border:1px solid black;
          width:100px;
          height:100px;
          overflow:hidden;
     }
     #block{
          padding:0px
     }
     #text{
          font:normal 10px verdana;
     }
     </style>
</head>
 
<body>
     <div id = "container">
          <div id="block">
               <img src = "image.png">
               <div id ="text">
                    Not the classic "Lorem Ipsum"
               </div>
          </div>
     </div>
</body>
 
</html>

Line 6: importing jQuery library

Line 8: we can call it a listener for the document to be ready. When it’s ready, it executes the function

Line 9: fading the content of the text element to transparent. This way I am starting with a transparent text. Obviously I can set this from the css declaration, but I wanted to do it with jQuery because it’s cool :)

Line 10: this is a listener for the container element. Listens for the mouse to be over it.

Line 11: stopping previous animations and moving the block element (the image with the text) up by 25 pixels and once the animation finishes, fades in the text element. This replicates the Gallery rollover effect, and I can display text on multiple rows. The overlow:hidden style at line 24 gives the feeling the image is sliding like a garage door and not simply moving.

Do not use relative positioning in block element or it won’t work on IE7 (yet anohter IE7 bug…)

Line 13: listener for the mouse leaving the container element

Line 14: fading away text element and moving the block element to its original position

And this is the result. As you can see it’s pretty similar to the original Gallery effect.

Move the mouse on the image and see

Download the source code with jQuery compressed library.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (7 votes, average: 4.86 out of 5)
Loading ... Loading ...
If you found this post useful, please consider a small donation.

2 Responses to “Interesting jQuery effect”

  1. RipeX on May 26th, 2009 1:31 am

    Really cool effect you got there! :D

Leave a Reply




Trackbacks

  1. Free web resources – Net-Kit.com » Blog Archive » 15 Excellent thumbnail gallery effects on December 2nd, 2009 3:18 pm

    [...] 11. Create a Stunning Sliding Door Effect with jQuery [...]

flash games company