$(window).on('resize', function () { if ($('.ngx-gallery-active').length) { RedimensionarImagenPrincipal(); } }); $(document).on('DOMNodeInserted', '.ngx-gallery-active', function () { RedimensionarImagenPrincipal(); }); function RedimensionarImagenPrincipal() { var image_url = $('.ngx-gallery-active').css('background-image'); if (image_url) { image_url = image_url.match(/^url\("?(.+?)"?\)$/); if (image_url[1]) { image_url = image_url[1]; image = new Image(); image.src = image_url; var mainWidth = $('ngx-gallery').width(); // var newHeight = (parseFloat(mainWidth) * parseFloat(image.height) / parseFloat(image.width));// + 150; // var newHeight = parseFloat(image.height); // + 150; // if (newHeight > 600) newHeight = 600; var newHeight = (mainWidth / parseFloat(image.width) * parseFloat(image.height)); if (newHeight > image.height) { newHeight = image.height; } if ($('.ngx-gallery-thumbnails').length) { newHeight += 150; } $('ngx-gallery').height(newHeight); if ( $('ngx-gallery').width() > image.width) { $('.ngx-gallery-image.ngx-gallery-active').width(image.width); } } } else { $('ngx-gallery').height(0); } }