This week I’d like to show you how you can create a kick-ass animated Shine Effect with jQuery & CSS3 and 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 live demo.
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 ; )
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:
- Change the margins of the thumbnail element so that it floats away from it’s container
- Set the background-position of your “shine” graphic to be –1 * (it’s total width)
- 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.
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.
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:
- CSS3 is 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.
- 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.
- 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)
- 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.
The Code
Finally, for the part you’ve been waiting for: the code.
HTML (Sample)
![]()
Welcome to ShineTime
CSS
body { background-color:#333; margin:0 auto;
background-image:url('images/interface/bgnoise.png');}
#container { width:793px; height:498px; margin:0 auto;
background-image:url('images/interface/back_noise.png');
background-color:#111; margin-top:40px;}
#container .mainframe { width: 500px; height:498px; float:left}
#container .thumbnails { float:left; width:293px; height:498px;
background-repeat:no-repeat; background-image:url('images/interface/total_grid.png');
background-position:9px 70px; }
.thumbnailimage { float:left; padding:7px;}
.large_thumb {float:left; position: relative; width:64px;
height:64px; padding:0px 10px 0px 0;}
img.large_thumb_image {position:absolute; left:5px; top:4px;}
.large_thumb_border {width:64px; height:64px;
background:url('images/interface/thumb_border.png'); position:absolute; }
.large_thumb_shine {width:54px; height:54px;
background:url('images/interface/shine.png'); position:absolute;
background-position:-150px 0; left:5px; top:4px; background-repeat:no-repeat;}
.thumb_container { width:64px; height:64px;
background-image:url('images/interface/thumb_holder.png'); }
#largephoto { width: 444px; height:370px; background-color:#333333;
margin-top:68px; margin-left:40px; -moz-border-radius: 10px;
-webkit-border-radius: 10px; border-left: 1px solid #fff;
border-right: 1px solid #fff; border-bottom: 1px solid #fff; }
#largetrans { width: 444px; height:370px;
background-image:url('images/interface/main_bg_trans.png');
-moz-border-radius: 10px; -webkit-border-radius: 10px;}
.large_image { display:none}
#containertitle { position:absolute; margin-top:35px;
margin-left:40px; font-family:Arial, Helvetica, sans-serif;
font-weight:bold; text-shadow: 0px 1px 2px #fff;}
#largecaption { text-align:center; height:100px;
width:100%; background-color:#111; position:absolute; width: 444px;
margin-top:270px; -moz-border-radius-bottomleft: 10px;
-moz-border-radius-bottomright: 10px; -webkit-border-bottom-left-radius: 10px;
-webkit-border-bottom-right-radius: 10px;
display:none; color:#fff; font-size:30px;
font-family:Arial; letter-spacing:-1px; font-weight:bold}
#largecaption .captionContent { padding:5px;}
#largecaption .captionShine { background:url('images/interface/bigshine.png');
position:absolute; width: 444px; height: 100px;
background-position:-150px 0;background-repeat:no-repeat;}
#loader { width:150px; height:150px;
background-image:url('images/interface/loader.gif');
background-repeat:no-repeat; position:absolute;}
JavaScript
$(document).ready(function()
{
/*Your ShineTime Welcome Image*/
var default_image = 'images/large/default.jpg';
var default_caption = 'Welcome to ShineTime';
/*Load The Default Image*/
loadPhoto(default_image, default_caption);
function loadPhoto($url, $caption)
{
/*Image pre-loader*/
showPreloader();
var img = new Image();
jQuery(img).load( function()
{
jQuery(img).hide();
hidePreloader();
}).attr({ "src": $url });
$('#largephoto').css('background-image','url("' + $url + '")');
$('#largephoto').data('caption', $caption);
}
/* When a thumbnail is clicked*/
$('.thumb_container').click(function()
{
var handler = $(this).find('.large_image');
var newsrc = handler.attr('src');
var newcaption = handler.attr('rel');
loadPhoto(newsrc, newcaption);
});
/*When the main photo is hovered over*/
$('#largephoto').hover(function()
{
var currentCaption = ($(this).data('caption'));
var largeCaption = $(this).find('#largecaption');
largeCaption.stop();
largeCaption.css('opacity','0.9');
largeCaption.find('.captionContent').html(currentCaption);
largeCaption.fadeIn()
largeCaption.find('.captionShine').stop();
largeCaption.find('.captionShine').css("background-position","-550px 0");
largeCaption.find('.captionShine').animate({backgroundPosition: '550px 0'},700);
Cufon.replace('.captionContent');
},
function()
{
var largeCaption = $(this).find('#largecaption');
largeCaption.find('.captionContent').html('');
largeCaption.fadeOut();
});
/* When a thumbnail is hovered over*/
$('.thumb_container').hover(function()
{
$(this).find(".large_thumb").stop().animate({marginLeft:-7, marginTop:-7},200);
$(this).find(".large_thumb_shine").stop();
$(this).find(".large_thumb_shine").css("background-position","-99px 0");
$(this).find(".large_thumb_shine").animate({backgroundPosition: '99px 0'},700);
}, function()
{
$(this).find(".large_thumb").stop().animate({marginLeft:0, marginTop:0},200);
});
function showPreloader()
{
$('#loader').css('background-image','url("images/interface/loader.gif")');
}
function hidePreloader()
{
$('#loader').css('background-image','url("")');
}
});
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 the ShineTime – A jQuery & CSS3 Gallery With Animated Shine Effects button!. Thanks, guys.



good
Pingback: jQuery & CSS3 Image Gallery With Animated Shine Effect
Congratulations on a great website.
Pingback: delicious Links: 16. December 2010 | miZine
Very nice …. thank you Addy
Pingback: Bling Bling Effekt mit jQuery » miZine
Pingback: 50 Best jQuery Techniques 2010 | webdesign14.com
Thanks for your Job !!!
I have do an adaptation for my french CMS : NPDS
you can see here http://www.jireck.com/static.php?op=shinetime.txt
hi everybody!
ist it possible putting a link (herf) into the largecaption or just linking the image "rel"? how can I do that?
looking forward…
Pingback: 40 Exceptional jQuery Photo Gallery and Slider | Free and Useful Online Resources for Designers and Developers
wooowww! great!
That's a neat little effect with the shine. It honestly never occurred to me to do shine effects like that, very smooth and professional. Thanks for that!
One performance tip for the code though, I noticed you're not caching your jQuery calls. For instance, in your 'thumb_container' hover function, you're performing 4 $(this) calls, so you're creating a jQuery object from the 'this' element, then discarding it and creating it again 3 more times. You can speed up your performance by caching your jQuery calls in local vars. For instance, if you do var $this = $(this), then when you access the local $this variable it will be an instantaneous lookup instead of running seperate jQuery calls. You can also cache the .finds you're doing in your 'largephoto' hover function. Just a cool little performance tip.
Pingback: Top 100 Useful And Detailed CSS3 Tutorials And Techniques « qeqnes | Designing. jQuery, Ajax, PHP, MySQL and Templates
Pingback: Webデザイン ホームページ制作 名古屋 豊橋 | creal クレアル - 画像を使ったjQueryプラグイン
Pingback: 40 Exceptional jQuery Photo Gallery and Slider
it’s so nice ! thank you
Pingback: nyentrik.com || Bleeding Edge Best Resources for Web Developers » How to Create Animated Shine Effect with jQuery & CSS3
Pingback: Cool and Useful jQuery Image and Content Sliders and Slideshows - Noupe Design Blog
This is a copy of Freshface's Creative Zodiac template on Themforest… you could at least credit the original which has been around for over a year.
http://themeforest.net/item/creative-zodiac-portf…
Pingback: Cool and Useful jQuery Image and Content Sliders and Slideshows | 20 One | Designers Blog20 One | Designers Blog
Pingback: Cool and Useful jQuery Image and Content Sliders and Slideshows
Pingback: Sacima鲨鳍马工作室 » Blog Archive » Cool and Useful jQuery Image and Content Sliders and Slideshows
Pingback: Beyond Traditional Image Showcase with jQuery | Hot Scripts Blog
Pingback: 60款很酷的 jQuery 幻灯片演示和下载 | 刀侠剑客
Pingback: 60款很酷的jQuery 幻灯片演示和下载 | 蓝枫's BLOG
Pingback: 钟代麒 » Blog Archive » 60款很酷的 jQuery 幻灯片演示和下载(转)
Pingback: 60款很酷的 jQuery 幻灯片演示和下载 | Artfans视觉杂志
Pingback: 60款很酷的 jQuery 幻灯片演示和下载 – 峰随意动,尽从容!
Pingback: Web Vision Design | Web Analytics, Tutorials, jQuery, CSS, PHP, Internet Marketing and Web Development | Web Vision Design
Pingback: 非常實用又漂亮的jQuery工具 (可免費下載喔!!) « 我是派
Pingback: Excelentes recursos para incluir SlideShows en sus Websites. « Recursos Web
Pingback: 值得收藏的jQuery幻灯片特效 | XIAOYE'S BLOG
Pingback: 190+ Best! jQuery Slider tools – Part IV - Pixel2Pixel Design
Pingback: 60款很酷的 jQuery 幻灯片演示和下载
Nice kickin Ass!
wonderful !! its jus so cool…I would like see pagination for the list of thumbnails…as there could be more than 15 thumbs , with a pagination or some navighation to other thumbs more than 15 its would be more gr8…..I hope to see soon the next version !!!
This is really an ass-kicker for this is awesome! This is an application many awaits on. Thank you for this.
Great code with great results. Very useful if you want to make a good impression! Just tweeted it.
thanks , very useful
Awesome technique brother, feel like eating up your Brains !
wooow cooool ! thanks for sahring !!!
Pingback: 60款jQuery 幻灯片 | 秦唐网
tnx alot
Pingback: 60款很酷的jQuery 幻灯片演示和下载 « Wondye's Blog
very good
Amazing. I will try this
cool such a nice work, salam from Indonesia
Pingback: 60款很酷的 jQuery 幻灯片 | 喜乐优
Pingback: 50 New Useful CSS Techniques, Tutorials and Tools « infirock
wow, what a amazing gallery man…
i'm purely impressed..