Magnify – a jQuery Plugin

Let me begin by saying right up front, I have not given up on Flash. Despite Adobe’s recent PR debacle which I’m sure if you’re reading this, you’re familiar with, I still love Flash and it’s still my bread and butter. When my wife wanted to put together a portfolio site to show off her fantastic photography and collage work, though, I figured it was as good a time as any to pick up some new skills. So I delved into the land of jQuery and HTML. Sort of 2001: A Javascript Odyssey.

While building the site (which still isn’t complete, but it’s coming along) I discovered I needed some sort of tool to magnify images. Now there are a lot of good jQuery zooming plugins out there, but seeing as how this was supposed to be a learning experience, I decided to write my own. You can check out the results here.

You’re welcome to use this, if you’d like (it’s available under MIT license), but here are a few caveats. First, it only works with single images that have been scaled down in the html page (the ‘magnified’ image is actually the size of the original image). Second, the image must be fully loaded (so that it has width, height, and src properties) and correctly positioned (so that its offset property is not simply {0, 0}). To use it, just say:

$(someImageSelector).magnify(originalImageWidth, originalImageHeight, optionsObject);

The optionsObject may contain the following properties:

  • width    the width of the ‘magnifying glass’    defaults to 200
  • height    the height of the ‘magnifying glass’    defaults to 200
  • useBorder    a boolean that determines whether or not to display a border around ‘magnifying glass’    defaults to true
  • borderSize    the size in pixels of the border    defaults to 1
  • borderColor    a string specifying the color of the border    defaults to ‘black’
  • useCrosshair    a boolean that determines whether or not to show a crosshair cursor    defaults to false
  • useShadow    a boolean that determines whether or not to show a dropshadow behind ‘magnifying glass’ (doesn’t work in IE)    defaults to true
  • animate    a boolean that determines whether or not ‘magnifying glass’ should fade in and out    defaults to true
  • hideMouse    a boolean that determines whether or not to show the mouse pointer (doesn’t work in Safari)    defaults to false

If you do a view source on the demo you can see in the site.js file how two different option objects are used. The download contains both the original commented file and a minified version (roughly 1.5 k in size).

DEMO    |    DOWNLOAD

Now, I am by no means a javascript or jQuery expert so I’m sure there may be better ways of doing some things. If anyone has any tips, don’t hesitate to post them. Happy early Christmas…

Incidentally, although my wife’s portfolio site isn’t done, take the time to check out her work over on Society 6 ( photography | collage ). You’ll be glad you did.

 

2 Comments »

  1. Hendrik says:

    Good job! Works very well.

    I’ve also recently been starting to do more with javascript/jQuery, but still looking for a good IDE. What do you use?

  2. Devon O. says:

    Hey Hendrik – I’ve actually been using FlashDevelop as a js IDE. Ain’t ideal for it, but it’s something I’m used to and comfortable with…

RSS feed for comments on this post. / TrackBack URI

Leave a Reply

Devon O. Wolfgang

Technical Reviewer of “The Essential Guide to Flash CS4 AIR Development”

Contributing Author of “Flash AS3 for Interactive Agencies”

Senior Flash Engineer PopCap Games, International Ltd.

Portfolio

Santabot: A Unity3D Flash Game


All right, so a Christmas game like “Santabot vs. The Flying Saucers from Mars” may be a day late[...]

Magnify – a jQuery Plugin


Let me begin by saying right up front, I have not given up on Flash[...]

It’s a Starling Halloween


Getting some practice for the upcoming Zombie Apocalypse[...]

Getting Started with Proscenium

So I had a chance this weekend to sit down and play around with Adobe’s new 3D framework for Stage3D, Proscenium, and thought I’d share a few of the results (a word of caution, there are no preloaders for any of the examples and may load a bit slowly). The first shows some reflections and [...]

Particle Editor for Starling Framework

An in-browser particle editor for the Starling 2D Framework for Flash Player 11.

So Long and Thanks for all the Flash on the Beach

So, another Flash on the Beach has just has just drawn to a close[...]

Game Development Tips from the Trenches of PopCap

Well, this is a post that’s a bit overdue, but, thanks to a well timed bank holiday, I finally had the opportunity to sit down and type up what I’ve been meaning to for some time now…

Old Skool Demoscene FX as 3D Textures

Many moons ago, I got the idea to create some demoscene plane deformation effects in Flash based on the formulas found here: http://www.iquilezles.org/www/articles/deform/deform.htm. I posted my less than desired results up on wonderfl. Thankfully, fellow wonderfl user, Hasufel, forked my attempt and optimized the hell out of it coming up with this. Well, today, for no [...]

Making The Gaming Scene (A Change in Careers)

And for my second blog post of the day, a much more personal note. After about three years of working with, what I would consider as objectively as possible, the best digital agency in Ireland, vStream Digital Media, I have made the immense career decision to leave the agency world and enter the arena of [...]

Feeling Lucky?

Images to dice, kick ascii style [...]

Adventures in Playbook Land

Adventures in Playbook Land


Now that the ordeal is over, I thought I’d take the time to sit down and share my account of what it was like to develop a Blackberry Playbook application using the Adobe Flex SDK[...]

Flash

Draw it for Me

So many ideas – so little time….

Kinect Application Running in Dublin

So, on Friday I just wrapped up our latest project at vStream Digital Media, a Kinect powered flipbook that lets users flip through the hand written notebooks of Philip Lynott of Thin Lizzy. The app uses OpenNI, runs in Adobe AIR and is currently on display at a pretty bitchin’ Phil Lynott exhibition running in [...]

Beach Ball Kinect Party

So we finally got a Kinect camera hooked up to a pc at work and, while it doesn’t seem to be legal to use it for commercial projects (but, hey, I’m no lawyer), the boss asked me to get it figured out and come up with some ideas just in case it would be feasible [...]

Facebook and Flash – A Book Review

Now, I should begin by saying I absolutely hate building Facebook applications. And I build a lot of them at work. Every time I get the word from above that we’re doing another FB app, I just groan – both inwardly and out. It’s become a running joke of the office. Why do I dislike [...]

Multitouch Fluid Dynamics with AIR for Android and RTMFP

The other day I was having some fun playing around with Eugene Zatepyakin’s (aka @inspirit) FluidSolverHD (Actionscript port of C++ fluid dynamics library, MSAFluid. Or is MSAFluid, the processing/java port of the C++ library? In any case it’s a very cool fluid dynamics thingamabob – the HD version using Alchemy). After a bit of tinkering, [...]