user5314029
user5314029

Reputation:

Get image height and then show

I want to load the image, determine the height, and THEN show it

Here is my code:

$("#block").animate({
        height: HERE GOES HEIGHT + 50px for additional space
    },
    function() {
        $("img").fadeIn("slow");
    });

Upvotes: 1

Views: 79

Answers (2)

user5314029
user5314029

Reputation:

Will this work?

$("img").load(function(){
var imgHeight = $(this).height();
});

$("#block").animate({
    height: '+='imgHeight
},
function() {
    $("img").fadeIn("slow");
});

Upvotes: 2

kwh71787
kwh71787

Reputation: 576

Grabbing the image dimensions before the page is loaded is not something I think is particularly possible like this.

However there is a similar post to grab the image dimensions before its fully loaded, then you could tie that into your animation.

Get image dimensions with Javascript before image has fully loaded

Upvotes: 1

Related Questions