When loading, I get real sizes of photos, in order to correctly change them with regard to proportions, I need to save these proportions later, they will come in handy for me later, but the values ​​of the arrays are beyond .load undefined. How to get these values?

var $img = $('.slide img'); var wid = new Array(); var hei = new Array(); var k = 0; $img.load(function () { $(this).removeAttr("width").removeAttr("height").css({ width: "", height: "" }); var width = $(this).width(); var height = $(this).height(); var kof = width / height; if (height >= 600) { var width = kof * 600; $(this).attr('height', '600'); $(this).attr('width', width); wid[k] = width; hei[k] = height; k += 1; } else { $(this).attr('height', height); $(this).attr('width', width); wid[k] = width; hei[k] = height; k += 1; } $('#slides').height(600); }); 

    1 answer 1

    Declare these arrays above load via var