[ACCEPTED]-Animate text size with jQuery then return to previous state-css

Accepted answer
Score: 11

This works and looks much better...

$(document).ready(function() {
    $('.button-1,.button-2,.button-3').each(function() {

        $(this).data('original-size', $(this).css('fontSize'));

        $(this).click(function() {

            $(this).animate({
                fontSize: "40px"
            }, 1000);

            $(this).siblings().each(function() {

                var originalSize = $(this).data('original-size');

                if ($(this).css('fontSize') != originalSize) {

                    $(this).animate({
                        fontSize: originalSize
                    }, 500);
                }
            });

        });
    });
});

jsFiddle.

If you 5 were lazy, you could also do...

$(this).siblings().removeAttr('style')

jsFiddle.

This solution, however, is 4 flaky and could lean to painful debugging if 3 you or jQuery adds extra styles via the 2 style attribute. I recommend you use the former 1 code.

Score: 4

Here's a shorter way to do it

$(document).ready(function() {
    $('.button-1,.button-2,.button-3').click(function() {
        $('div').removeClass('button-4', 50);
        $(this).addClass('button-4', 100);

    });
});

Check working 1 example at http://jsfiddle.net/nLnvY/2/

More Related questions