Tutorial: jQuery effect – how to shrink/zoom at the center of a container

jQuery provides a basic effect of sliding in and out. However, in other to create other form of effect we will have to apply animate function provided by jQuery. This tutorial will demonstrate of using animate function in jQuery to perform a shrink function at the center of an element  that you often see in Gallery and other types of plugin.

It is not difficult to create a method to demonstrate a shrink in and out effect with animate function. The concept used here is to opposite the natural direction of the sliding jQuery provides in order to zoom in the image shows below.

hungred2 Tutorial: jQuery effect   how to shrink/zoom at the center of a
container

image to be zoom

Yes! Its RAWR! cute ghost, i was lazy to find a proper picture so i just grab him down to play with.  Now, in order to shrink him properly, we will have to use the plugin i created just for him. I will also explain what does this simple plugin does. You can have a look at the demo below,

demo-rawrzoom

PS: There is another method which is  a bit more complex than this one which you can see from here

So, how does the plugin work? Simple! it’s just pure animate function from jquery with css. Illustrator the code below.

$(selector).stop(true,false)
.animate({
height: options.zoomSize+'px',
width: options.zoomSize+'px',
marginTop: ((oriH-options.zoomSize)/2)+'px',
marginLeft: ((oriW-options.zoomSize)/2)+'px'
}, options.duration)

What it does here is to shrink it to the size you define and move opposite accordingly. Let’s assume height: and width: move upwards and right respectively while it shrink. So marginTop: and marginLeft: will move downwards and left respectively so that our eyes will illustrate the shrink on the center of the box! hopes this help!

Usage

An example on how to use this plugin from the demo site. The parameter is optional.

$('#zoomMe').zoom(
{
zoomWidth: 10,
zoomHeight: 10,
duration: 3000
}
);

or

$('#zoomMe').zoom();

Parameter

The optional parameter for this plugin is as follow,

  • zoomwidth: the width you wish it to be minimize default its 10
  • zoomheight: the height you wish it to be minimize defaults its 10
  • duration: time for zoom to be complete defaults its 5000

You can download the plugin from

 

Like this post? Share it!

digg 48 Tutorial: jQuery effect   how to shrink/zoom at the center of a
container reddit 48 Tutorial: jQuery effect   how to shrink/zoom at the center of a
container stumbleupon 48 Tutorial: jQuery effect   how to shrink/zoom at the center of a
container delicious 48 Tutorial: jQuery effect   how to shrink/zoom at the center of a
container furl 48 Tutorial: jQuery effect   how to shrink/zoom at the center of a
container technorati 48 Tutorial: jQuery effect   how to shrink/zoom at the center of a
container google 48 Tutorial: jQuery effect   how to shrink/zoom at the center of a
container myspace 48 Tutorial: jQuery effect   how to shrink/zoom at the center of a
container facebook 48 Tutorial: jQuery effect   how to shrink/zoom at the center of a
container twitter 48 Tutorial: jQuery effect   how to shrink/zoom at the center of a
container
share save 171 16 Tutorial: jQuery effect   how to shrink/zoom at the center of a
container

No related posts.

About Clay

I am Clay who is the main writer for this website. I own a small web hosting company in Malaysia and i'm available to be hired as individual contractor on elance. You can find me on twitter.
This entry was posted in How-to, jQuery and tagged . Bookmark the permalink.

2 Responses to Tutorial: jQuery effect – how to shrink/zoom at the center of a container

  1. Nobody says:

    Hmm… .each() in combination with globals? interesting.
    Ever tried $(“.class”).zoom(..) with images of different size but same class?

  2. Clay Lua says:

    should also work tho. but i haven’t had the chance to try with different image size yet with this plugin. Tell me if it doesn’t because i believe there is a need for a wrapper around the image to contain the resizing of the image or else the image will move straight to the left screen. Other than that i do believe different size will also zoom properly =)