Skip to content

ara pehlivanian

Web Standards, Web Culture, Web Everything.™

Automated JavaScript Vertical Flip Image Reflection

MeDo you see it? Look closely, now do you see it? Look around the site a little. If you’re using either Firefox 1.5+, Safari or Opera 9+ you should be seeing a reflection under the images in the post body–thanks to the Reflection script I just wrote. No Java applets, no Flash, just pure JavaScript. And it’s relatively light and fast too–each reflection consists of just one new DOM element. Here, check out this example page.

The script allows you to modify opacity and depth and comes with three different ways of passing images to the reflection object (by ID, by class name or just a raw array you build yourself).

A basic implementation looks like this:

<script type="text/javascript" src="reflect.js"></script>
window.onload = function(){
	var reflections = new ARA.effects.Reflection();
		reflections.addImage("myImageID");
		reflections.reflect();
}

A more advanced implementation looks like this:

<script type="text/javascript" src="reflect.js"></script>
window.onload = function(){
	var reflections = new ARA.effects.Reflection();
		reflections.addImage("me");
		var imgs = [];
			imgs.push(document.getElementById(”csarvenWLGreen”));
			imgs.push(document.getElementById(”microformats”));
		reflections.addImagesRaw(imgs);
		reflections.addImagesByClassName(”reflect”);
		reflections.addImagesByClassName(”reflect1″, {startPoint:”group”,alpha:.75,depth:10});
		reflections.reflect();
}

The JavaScript code is documented as well so you should be able to get a head start. I’ll write up more detailed docs if and when interest grows. If you’re interested in implementing it on your own site you can download the reflect.js file or the entire zipped example. Remember, the script only works on Firefox 1.5+, Opera 9+ and Safari (though I’ve only tested it on Firefox so let me know if it works on the others).

Enjoy! And as always, your feedback would be much appreciated.

Update: In a turn of dumb misfortune, I found out after releasing this, that someone had already coded an extremely similar implementation (with IE support) last year! Oh well, you do what you can I guess…

Sphere: Related Content

  • Comments closed

Buy my book

The Art & Science of JavaScript / SitePoint
The Art & Science of JavaScript

Advertisement

Firebug - Web Development Evolved

Advertisement

18 Comments

  1. Gravatar for LukeLuke says:

    Nice! You are all over teh javascripts lately, eh?

  2. Gravatar for stevesteve says:

    This site (not mine):
    http://cow.neondragon.net/stuff/reflection/

    Created a JS implementation for this also, that works in IE too, by using IE’s Alpha Transformations…

    I hate to extend a hand to IE here, but since so many users haven’t abandoned it yet (oh my, was that a dig?… oh dear), adding similar functionality to your script might be handy.

    Cheers,
    Steve

  3. Gravatar for Ara PehlivanianAra Pehlivanian says:

    Steve: See my latest post, “Elisha Gray”

    (http://arapehlivanian.com/2007/02/20/elisha-gray/)

  4. Gravatar for AJAJ says:

    Hi,
    This is really cool. And should be quite easy to use it. I’ll give it a spin.

  5. Gravatar for ArashArash says:

    Good job :-) Also any way it could be developed such that one could animate it (resize, move, fade in out, turn) the image while the reflection stays intact ?

  6. Gravatar for evanevan says:

    Great Job, however it does not seem to be working in Safari.

    -evan

  7. Gravatar for Baz Web Development: AJAX, Joomla, CSS » Blog Archive » More JavaScript Reflections - Automated JavaScript Vertical Flip Image ReflectionBaz Web Development: AJAX, Joomla, CSS » Blog Archive » More JavaScript Reflections - Automated JavaScript Vertical Flip Image Reflection says:

    [...] not sure what to make of this: Automated JavaScript Vertical Flip Image Reflection. It adds reflections to images using JavaScript. But, am I missing something here, or has it [...]

  8. Gravatar for Mukul KumarMukul Kumar says:

    Very cool. Nice job.

  9. Gravatar for coolnalucoolnalu says:

    Nice thoughts. Really inspiring…

  10. Gravatar for Dawn of Hero [英雄的黎明] » Blog Archive » Reflection on Web Page, Purely based on Javascript and DOM manipulationDawn of Hero [英雄的黎明] » Blog Archive » Reflection on Web Page, Purely based on Javascript and DOM manipulation says:

    [...] morning, from Ajaxian.com, I saw link to a post in which the author mentioned his reflection generating script. It’s implemented based on canvas, which isn’t supported by IE at all but sufficiently [...]

  11. Gravatar for Javier NareseJavier Narese says:

    nice job… but in IE7 don’t work :(

  12. Gravatar for Ara PehlivanianAra Pehlivanian says:

    Javier: I know, it wasn’t intended to work in IE. And apparently it’s buggy in Safari. :-/

  13. Gravatar for Alessandro Melandri » Blog Archive » Javascript image reflectionAlessandro Melandri » Blog Archive » Javascript image reflection says:

    [...] Pehlivanian has just released a nice javascript that creates vertical flip image reflections adding only a DOM element. This really nice! Check it [...]

  14. Gravatar for Mike SmithMike Smith says:

    Hi,

    This is really cool. And should be quite easy to use it. I’ll give it a spin.

  15. Gravatar for spring-comingspring-coming says:

    nice! but doesn’t work in IE 6.0

    I saw excellent image reflection examples at

    http://www.featurepics.com/Editorial/Image-Reflection-Special-Effect.aspx

    I think neondragon.net script has been used

  16. Gravatar for Blog de programación » Archivo del weblog » Imágenes con efecto espejo (con Javascript)Blog de programación » Archivo del weblog » Imágenes con efecto espejo (con Javascript) says:

    [...] La web del autor [...]

  17. Gravatar for Givatry » Archive » JavaScript/DOM ReflectorGivatry » Archive » JavaScript/DOM Reflector says:

    [...] morning, from Ajaxian.com, I saw link to a post in which the author mentioned his reflection generating script. It’s implemented based on canvas, which isn’t supported by IE at all but sufficiently covers [...]

  18. Gravatar for Melandri.net » Javascript image reflectionMelandri.net » Javascript image reflection says:

    [...] Pehlivanian ha appena pubblicato un fantastico javascript che permette di aggiungere alle immagini un riflesso verticale aggiungendo solamente un elemento [...]

Sorry, the comment form is closed at this time.

Skip to navigation

More stuff by Ara elsewhere on the web

    Snook Approved!

    © 2005-2008, Ara Pehlivanian.

    Stock photography courtesy stock.xchng. This site uses Akismet to catch spam (54,743 caught since May 2006) is hosted by DreamHost and powered by WordPress.