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.
2 Responses to “Interesting jQuery effect”
Leave a Reply
Trackbacks
-
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 [...]
- Citrus Engine released for free for learning
- My epic fail with ClickBank
- Get up to $100,000 for your next Flash game with Mochi GAME Developer Fund
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines – 17 lines version
- Sell sitelocked version of your Flash games and even .fla sources to Free Online Games
- Protect your work from ActionScript code theft with SWF Protector
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines
- Understanding Box2D’s one-way platforms, aka CLOUDS
- Triqui MochiAds Arcade plugin for WordPress upgraded to 1.2
- Box2D Flash game creation tutorial – part 2
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 1
- Create a Flash Racing Game Tutorial
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash draw game like Line Rider or others - part 1
- Triqui MochiAds Arcade plugin for WordPress official page
- Create a flash artillery game - step 1
- Flash game creation tutorial – part 5.2 (4.88/5)
- Create a flash artillery game – step 1 (4.79/5)
- Create a Flash Racing Game Tutorial (4.76/5)
- Create a survival horror game in Flash tutorial – part 1 (4.74/5)
- Create a flash artillery game – step 2 (4.74/5)
- Creation of a Flash arcade site using WordPress – step 2 (4.73/5)
- Flash game creation tutorial – part 1 (4.71/5)
- Flash game creation tutorial – part 2 (4.71/5)
- Create a flash draw game like Line Rider or others – part 1 (4.69/5)
- Creation of a platform game with Flash – step 2 (4.68/5)

(7 votes, average: 4.86 out of 5)



Really cool effect you got there! :D