Help with jquery function

0

Greetings. I have this jquery that assigns the height to a div in relation to a daughter image.

$(window).load(function(){
var alto = $('#bigPic img').height(); //alto de la imagen
$('#bigPic').height(alto * 1.1); }); //alto div = alto imagen * 1.1

And this one that changes the height of the div in relation to the same image only when the window size changes (not when loading the page)

$(window).resize(function () {
$('#bigPic').height($('#bigPic img').height() * 1.1);});
$(window).trigger('resize');

How would you do that to merge the two functions or that the resize works to the also when loading the page. Thank you very much.

    
asked by Daniel 26.05.2017 в 18:13
source

1 answer

1

Create a function:

var resize_ = function () {
    var alto = $('#bigPic img').height(); //alto de la imagen
    $('#bigPic').height(alto * 1.1); }); //alto div = alto imagen * 1.1
}

Then you invoke it where you need it:

var resize_ = function () {
        var alto = $('#bigPic img').height(); //alto de la imagen
        $('#bigPic').height(alto * 1.1); //alto div = alto imagen * 1.1
    }

  $( window ).on( "load", function() {
    alert("paso");
    resize_ (); 
  });

$(window).resize(function() {
    resize_ ();
});

So the resize function works for you in both events, which is what you ask.

Greetings,

    
answered by 26.05.2017 / 18:26
source