Saturday, December 29, 2007

jquery way to limit image size.

Find all images under current box, and limit their width to at most the same as current box.

        var w = $(this).width();
        $(this).find("img").each(function() {
            if ( $(this).width() > w ) {
                $(this).width("100%");
            }
        });

This is something similar to always wrap a div around an image. Only it's a piece of un-obstructive javascript instead of over-augmented-semantic-hack-sorting-out-bad-css-box-model.

This generally works good on Firefox, IE7. Didn't try others.

0 意見:

My Bicycle Rides