G
G
grafGG2014-12-06 22:16:47
JavaScript
grafGG, 2014-12-06 22:16:47

After uploading a photo using AJAX method, resize function (JQuery) doesn't work?

$(window).resize(function(){
    var window_width = $('#box').width();
    var window_height = $('#box').height();
    console.log (window_width);
    console.log (window_height);
    
    var img_width = $(".gallery-item img").attr("width");
    var img_height = $(".gallery-item img").attr("height");
    console.log (img_width);
    console.log (img_height);
    
    
    var style_margin_top = 0;
    var style_margin_left = 0;
    
    var new_width = 0;
        var new_height = 0;
    var ratio_width_to_height = img_width/img_height;
        var ratio_height_to_width = img_height/img_width;

        if((window_width * ratio_height_to_width) >= window_height) {
      new_width = window_width;
      new_height = window_width * ratio_height_to_width;
        
      style_margin_left = 0;
      style_margin_top = (window_height - new_height) / 2;
        } else {
      new_width = window_height * ratio_width_to_height;
      new_height = window_height;
      
      style_margin_left = (window_width - new_width) / 2;
      style_margin_top = 0;
        };
      
    $(".gallery-item img").css('marginTop', style_margin_top).css('marginLeft', style_margin_left).attr({"width" : new_width,"height" : new_height});
}).load(function(){
  $(window).resize();
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2014-12-07
@BuriK666

api.jquery.com/load
what you used is not clear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question