JQuery – How to i smoothly resize an image to create a pulsating effect

effectimagejqueryresizescale

Hey, Im working on a website with a friend of mine, and from the start, our client has been unhappy with the quality of one of our animations. This animation takes an image and makes it larger, it then makes it smaller, and repeats to get a pulsating effect. The opacity also changes throughout the animation.

The current animation is on the home page of the site http://laveryrowe.com. The animation in question is the 75% image that you can see immediately upon arriving at the site.

I have tested in safari, firefox and internet explorer. The animation only just about makes the cut in firefox, however safari and internet explorer do not produce smooth enough resizes for our client.

Does anyone know of a better method of animating than the one i have used? (see code below and check out the site for an example).

function pulse() {
    $('#seventyfive').animate({
        marginTop: 175, 
        marginLeft: 25, 
        width: 261, height: 98, 
        opacity: 0.5
    }, 700, function() {
        $('#seventyfive').animate({
            marginTop: 161.95, 
            marginLeft: 15.2, 
            width: 287.1, height: 107.8, 
            opacity: 1
        }, 700, function() {
            pulse();
        });
    }); 
};

Many thanks in advance, We could really use a hand,

Edit: The issue isn't with the positioning, (or at least i don't think it is) instead, its more to do with the way the image is resized, you can notice the jittery edges as it gets bigger. It seems to look better as the opacity is increased, but i need the same quality for when it is opaque.

Jai

Best Answer

Your animation isn't smooth because your marginLeft gets rounded down (image moves to the left one pixel) and then your width gets rounded up (image pixels are moved right just a little because they are re-sampled to a larger width.) Even though the image didn't move right your eyes tell you that it did because they perceive the middle of the image as being slightly to the right. This along with doing the same thing vertically makes the animation appear to jump around.

Here's an example of why I think the edges seem to flicker or shake. Below Are two images both 3 by 1 pixels. They are both resized to 5 by 1 and moved 4 pixels to the left. The blue one is what you are seeing where the size and location change independently. The red one only allows the size to change when the location changes and should appear to be a smooth animation.

enter image description here