brandonaaron / jquery-cssHooks

Collection of cssHooks that work with jQuery 1.4.3+
Other
478 stars 80 forks source link

how to make borderradiusalt animate individual radii #31

Closed amark closed 6 years ago

amark commented 13 years ago

(I'm not good at the whole forking / merging thing, so pardon in advance, here is a patch.)

This is not well written code, but it works - I am sure somebody could optimize it:

function ii(n){
    if(!n) {
        return [0]; 
    } else if(typeof n == 'number') {
        return [n] 
    } else {
    r = n.match(/(\-\d+|\d+)/g) || [0];
    for(var i in r) {
        r[i] = parseInt(r[i]);
    }
    return r;
}}
$.fx.step[ "border" + dir + "Radius" ] = function( fx ) {
                if(!fx.endx) {
                    var i = ii($(fx.elem).css("border" + dir + "Radius"));
                    fx.startx = i[0];
                    fx.starty = i[1]||i[0];
                    fx.f = ii(fx.end);
                    fx.endx = fx.f[0];
                    fx.endy = fx.f[1]||fx.f[0];

                    if((fx.endy - fx.starty) < (fx.endx - fx.startx)){
                        fx.which = true;
                        fx.end = fx.endx;
                        fx.start = fx.startx;
                        fx.now = fx.start;
                        fx.now2 = fx.starty;
                    } else {
                        fx.which = false;
                        fx.end = fx.endy;
                        fx.start = fx.starty;
                        fx.now = fx.start;
                        fx.now2 = fx.startx;
                    }
                }
                fx.now2 = (fx.which)?
                    fx.starty + ((fx.endy - fx.starty) * fx.pos)
                :
                    fx.startx + ((fx.endx - fx.startx) * fx.pos);
                var set = (fx.which)?
                    (fx.now + fx.unit+" "+fx.now2 + fx.unit)
                :
                    (fx.now2 + fx.unit+" "+fx.now + fx.unit);
                $.cssHooks[ "border" + dir + "Radius" ].set( fx.elem, 
                    set
                );
            };
tomgrohl commented 13 years ago

Thanks for your input, this cssHook is overdue some work/improvements so I'll take into account what you've done here and see how it can be moved into the cssHook. Looks like it may be of some use.

Thanks!