Aug 07 2007

YUI-based Image Magnifier Widget

Published by Julien Lecomte at 10:59 am under Web Development

I wrote a prototype YUI-based image magnifier widget that makes use of VML on Internet Explorer and the Canvas tag on all the other A-grade browsers. Attached is a screenshot.

To instantiate the widget, include the following source files in your web page (requires YUI >= 2.3)


<!-- CSS -->
<link rel="stylesheet" type="text/css" href="image-magnifier.css">

<!-- Dependencies -->
<script src="yahoo-dom-event.js"></script>
<script src="dragdrop-min.js"></script>

<!-- Image cropper source file -->
<script src="image-magnifier-min.js"></script>

Then, place an image on your page:

<img src="myImage.jpg" id="myImageId">

Finally, instantiate the widget:

<script>
    new YAHOO.widget.ImageMagnifier("myImageId", "magnified.jpg");
</script>

Although this prototype is not extremely polished, it should work fairly well right out of the box. Here is a live demo of the image magnifier widget (drag the lens around). You can also download an archive containing all the necessary source code.

2 Responses to “YUI-based Image Magnifier Widget”

  1. Adam Plattion 09 Aug 2007 at 8:52 am

    Nice job! It works really well in Safari, IE seems okay (slighly jumpy), and pretty sluggish in Firefox (on a mac at least).

    Do you think there are optimizations possible to make Firefox work better? IE is probably acceptable.

    Sweet dude!!

  2. Julien Lecomteon 09 Aug 2007 at 4:55 pm

    On a Windows box, I get almost the same level of performance on Firefox 2 and Safari 3. The difference you are seeing may be due to specifics of the canvas implementation in Firefox on the Mac.

Comments RSS

Leave a Reply