Set Width / Height by Percentage (ratio) using jQuery, CSS

$(document).ready(function() {
    
        var maxWidth = 100; // Max width for the image
        var maxHeight = 100;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
        var width = $(this).width();    // Current image width
        var height = $(this).height();  // Current image height
        $(this).css("width", width * ratio);    // Scale width based on ratio

});

Previous
Next Post »