ShineTime – A Kick-Ass New jQuery & CSS3 Gallery With Animated Shine Effects

jkick

This week I’d like to show you how you can create a kick-ass animatedShine Effect with jQuery & CSS3and then use it to create your very own Shiny Gallery ‘ShineTime’. This effect is useful in making your user interface elements look like they’re a real polaroid photo (or made of glass) and the best part is, it’s not that difficult to achieve. I always think it’s useful to see a demo of what we’re making before we look at it, so click here to check out the livedemo.image

You’ll also learn today how you can successfully use layering in your designs to give your gallery that extra bit of detail that can make it stand out from the others. Whilst I’m going to leave it to David Walsh to provide you with galleries full of Christina Ricci photos, today’s component includes a set of pictures from the movie ‘Kick-Ass’ for no other reason than because ; )

image

imageimage

The Animated ‘Shine’ Effect

The idea behind a Shine Effect is to give your graphics the appearance of being on a glossy surface that have just had a light beam pass over them. This can make them appear to be made of glass and can increase the visual experience your end users see.

Before we get into any code, lets go through the basic concepts behind the effect. We want to pass a light-beam (in this case an image simulating a shine) past our image when the user hovers over it. Now because I wanted to style up today’s gallery so that each thumbnail appeared to float out of it’s container, the steps to achieving the below animation are as follows:

  1. Change the margins of the thumbnail element so that it floats away from it’s container
  2. Set the background-position of your “shine” graphic to be –1 * (it’s total width)
  3. Animate your background-position to value of the total width. Effectively we’re hiding the gloss off-stage and then animating it across the image.

You can see this being achieved in the diagram below.

image

Now, because ShineTime is going to also apply this effect to the caption holder component (see the demo), I needed to come up with a much larger shine graphic for this that cleanly executes the desired effect without being slow or making the text unreadable. Using an image about 20% longer than the container in each direction at a layer below the text made this possible.

image

Designing ShineTime

Graphics-wise, there are a few important things to note about ShineTime. I wanted to give this demo an extra-depth of design detail so the following techniques were applied to create the final main-photo area:

  1. CSS3is used to create the rounded-corner borders around the main container div. It is also used on the indented shadow layer (which you can see below). In order for the caption container to also fit this design spec, it’s bottom rounded corners use CSS3 to keep everything looking like it’s inside the same box.
  2. Layering is heavily used in this demo to achieve a photographic-depth effect. The choice to do this using an image rather than CSS3 was in order to preserve the effect displaying in browsers like IE6.
  3. Normally, image galleries are based on UL/LI elements which are wrapped together using jQuery & CSS to turn them into something pretty. Here, because the actual image needs to be behind a few other layers so that it can have (a) Rounded corners and (b) the photo-effect, it’s necessary for all images to be loaded using the background-image property of the ‘largephoto’ div (take a look at the HTML code to see what I’m talking about)
  4. CSS3 is finally also used on the ShineTime Header. Whilst I’ve included Cufon for a little added cleanliness to my typographic elements, in the header it’s simply used for adding an indented feel to the text to give the background that extra ‘metallic’ feel to it.

image

The Code

Finally, for the part you’ve been waiting for: the code.

HTML (Sample)

  1. <divclass="thumbnailimage">
  2. <divclass="thumb_container">
  3. <divclass="large_thumb"><imgsrc="images/thumbnails/sample1.jpg"class="large_thumb_image"alt="thumb"><imgalt=""src="images/large/sample1.jpg"class="large_image"rel="JustbecauseIcan'tcode,
  4. doesn'tmeanIcan'tkickyourass!">
  5. <divclass="large_thumb_border"></div>
  6. <divclass="large_thumb_shine"></div>
  7. </div>
  8. </div>
  9. </div>
  10. <divid="containertitle">WelcometoShineTime</div>
  11. <divclass="mainframe">
  12. <divid="largephoto">
  13. <divid="loader"></div>
  14. <divid="largecaption">
  15. <divclass="captionShine"></div>
  16. <divclass="captionContent"></div>
  17. </div>
  18. <divid="largetrans"></div>
  19. </div>
  20. </div>

CSS

  1. body{background-color:#333;margin:0auto;
  2. background-image:url('images/interface/bgnoise.png');}
  3. #container{width:793px;height:498px;margin:0auto;
  4. background-image:url('images/interface/back_noise.png');
  5. background-color:#111;margin-top:40px;}
  6. #container.mainframe{width:500px;height:498px;float:left}
  7. #container.thumbnails{float:left;width:293px;height:498px;
  8. background-repeat:no-repeat;background-image:url('images/interface/total_grid.png');
  9. background-position:9px70px;}
  10. .thumbnailimage{float:left;padding:7px;}
  11. .large_thumb{float:left;position:relative;width:64px;
  12. height:64px;padding:0px10px0px0;}
  13. img.large_thumb_image{position:absolute;left:5px;top:4px;}
  14. .large_thumb_border{width:64px;height:64px;
  15. background:url('images/interface/thumb_border.png');position:absolute;}
  16. .large_thumb_shine{width:54px;height:54px;
  17. background:url('images/interface/shine.png');position:absolute;
  18. background-position:-150px0;left:5px;top:4px;background-repeat:no-repeat;}
  19. .thumb_container{width:64px;height:64px;
  20. background-image:url('images/interface/thumb_holder.png');}
  21. #largephoto{width:444px;height:370px;background-color:#333333;
  22. margin-top:68px;margin-left:40px;-moz-border-radius:10px;
  23. -webkit-border-radius:10px;border-left:1pxsolid#fff;
  24. border-right:1pxsolid#fff;border-bottom:1pxsolid#fff;}
  25. #largetrans{width:444px;height:370px;
  26. background-image:url('images/interface/main_bg_trans.png');
  27. -moz-border-radius:10px;-webkit-border-radius:10px;}
  28. .large_image{display:none}
  29. #containertitle{position:absolute;margin-top:35px;
  30. margin-left:40px;font-family:Arial,Helvetica,sans-serif;
  31. font-weight:bold;text-shadow:0px1px2px#fff;}
  32. #largecaption{text-align:center;height:100px;
  33. width:100%;background-color:#111;position:absolute;width:444px;
  34. margin-top:270px;-moz-border-radius-bottomleft:10px;
  35. -moz-border-radius-bottomright:10px;-webkit-border-bottom-left-radius:10px;
  36. -webkit-border-bottom-rightright-radius:10px;
  37. display:none;color:#fff;font-size:30px;
  38. font-family:Arial;letter-spacing:-1px;font-weight:bold}
  39. #largecaption.captionContent{padding:5px;}
  40. #largecaption.captionShine{background:url('images/interface/bigshine.png');
  41. position:absolute;width:444px;height:100px;
  42. background-position:-150px0;background-repeat:no-repeat;}
  43. #loader{width:150px;height:150px;
  44. background-image:url('images/interface/loader.gif');
  45. background-repeat:no-repeat;position:absolute;}

JavaScript

  1. $(document).ready(function()
  2. {
  3. /*YourShineTimeWelcomeImage*/
  4. vardefault_image='images/large/default.jpg';
  5. vardefault_caption='WelcometoShineTime';
  6. /*LoadTheDefaultImage*/
  7. loadPhoto(default_image,default_caption);
  8. functionloadPhoto($url,$caption)
  9. {
  10. /*Imagepre-loader*/
  11. showPreloader();
  12. varimg=newImage();
  13. jQuery(img).load(function()
  14. {
  15. jQuery(img).hide();
  16. hidePreloader();
  17. }).attr({"src":$url});
  18. $('#largephoto').css('background-image','url("'+$url+'")');
  19. $('#largephoto').data('caption',$caption);
  20. }
  21. /*Whenathumbnailisclicked*/
  22. $('.thumb_container').click(function()
  23. {
  24. varhandler=$(this).find('.large_image');
  25. varnewsrc=handler.attr('src');
  26. varnewcaption=handler.attr('rel');
  27. loadPhoto(newsrc,newcaption);
  28. });
  29. /*Whenthemainphotoishoveredover*/
  30. $('#largephoto').hover(function()
  31. {
  32. varcurrentCaption=($(this).data('caption'));
  33. varlargeCaption=$(this).find('#largecaption');
  34. largeCaption.stop();
  35. largeCaption.css('opacity','0.9');
  36. largeCaption.find('.captionContent').html(currentCaption);
  37. largeCaption.fadeIn()
  38. largeCaption.find('.captionShine').stop();
  39. largeCaption.find('.captionShine').css("background-position","-550px0");
  40. largeCaption.find('.captionShine').animate({backgroundPosition:'550px0'},700);
  41. Cufon.replace('.captionContent');
  42. },
  43. function()
  44. {
  45. varlargeCaption=$(this).find('#largecaption');
  46. largeCaption.find('.captionContent').html('');
  47. largeCaption.fadeOut();
  48. });
  49. /*Whenathumbnailishoveredover*/
  50. $('.thumb_container').hover(function()
  51. {
  52. $(this).find(".large_thumb").stop().animate({marginLeft:-7,marginTop:-7},200);
  53. $(this).find(".large_thumb_shine").stop();
  54. $(this).find(".large_thumb_shine").css("background-position","-99px0");
  55. $(this).find(".large_thumb_shine").animate({backgroundPosition:'99px0'},700);
  56. },function()
  57. {
  58. $(this).find(".large_thumb").stop().animate({marginLeft:0,marginTop:0},200);
  59. });
  60. functionshowPreloader()
  61. {
  62. $('#loader').css('background-image','url("images/interface/loader.gif")');
  63. }
  64. functionhidePreloader()
  65. {
  66. $('#loader').css('background-image','url("")');
  67. }
  68. });

Download, Demo & Screencast

Screencast:http://screenr.com/Z0W
Demo:http://www.addyosmani.com/resources/shinetime
Download:http://www.addyosmani.com/resources/shinetime/shinetime.1.01.zip

I hope that you found today’s post a little helpful. If you’d like to share it with your friends and colleagues or give me a thumbs up, feel free to click theShineTime – A jQuery & CSS3 Gallery With Animated Shine Effectsbutton!. Thanks, guys.

原文地址:ShineTime – A Kick-Ass New jQuery & CSS3 Gallery With Animated Shine Effects

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值