Hi,

> I'm not sure how to change the line:
> setTimeout("zoom_in()",time_length)
> to that the function can call itself.  Help appreciated.

I'd suggest to split it in two functions as many parts of jQuery itsself do:

jQuery.zoom_in = function(elm,time,step,callback) {
        var e = $(elm);

        if( !e.is('img') ) return;

        var w = e.attr("width");

        if( w == 0 ) elm.border = 0;
        else {
                var newWidth = w + step;
                var ratio = e.attr("height") / w;

                if(newWidth < max_width) {
                        e.attr("width", newWidth).
                          attr("height", Math.round(newWidth*ratio));

                        window.setTimeout(function() {
                                jQuery.zoom_in(elm,time,step,callback);
                        },time);
                } else callback.apply(elm,[]);
        }
}

jQuery.zoom_in.defaultTime = 42;
jQuery.zoom_in.defaultStep = 42;
jQuery.zoom_in.defaultCallback = function(){};

jQuery.fn.zoom_in() {
        var i = 0;

        var time = jQuery.zoom_in.defaultTime;
        if( typeof arguments[i] == 'number' && isFinite(arguments[i]) )
                time = arguments[i++];

        var step = jQuery.zoom_in.defaultStep;
        if( typeof arguments[i] == 'number' && isFinite(arguments[i]) )
                step = arguments[i++];

        var callback = jQuery.zoom_in.defaultCallback;
        if( typeof arguments[i] == 'function' )
                callback = arguments[i];

        return this.each(function() {
                jQuery.zoom_in(this,time,step,callback);
        });
}

You don't need to test for the parameters again and again and your 
timeout-function doesn't need 'this' set correctly.

If you like to use the pause-plugin 
(http://blog.mythin.net/projects/jquery.php), you can write

if(newWidth < max_width) {
        e.attr("width", newWidth).
          attr("height", Math.round(newWidth*image_scale)).
          pause(time).
          zoom_in(time,callback);
} else callback.apply(elm,[]);

But that needs a bit more CPU-ressources, because you call the function 
jQuery.fn.zoom_in() which tests for the given parameters again and again. If 
you whant to scale many pictures on the page simultaniously, don't use it.

Christof

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to