Get height of container with responsive image

Finduilas

I'm trying to position a div (intro-text) in another div (intro-container). I use css and jQuery to do that.

.intro-text {
width: 35%;
margin-left: auto;
margin-right: auto;
display: block;
}

In the div (intro-text) there is an image that has a responsive width / height. It has a width of 35% of the parent container (intro-container).

I needthe height of the intro-text div to position it in the container. It works fine, except on the first load. It returns 40px (the height of the text).

$(document).ready(function(){

        backgroundResize();

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

function backgroundResize(){
console.log("height:" + $(".intro-text").height());
}

It seems that the image isn't loaded yet, so it returns the wrong value.. Even if use document ready.. How can I fix this?

<div class="intro-container container">
    <div class="intro-text">
  <p><img src="intro.png"><br>
Address, Phone, .</p>
    </div>
</div>
selami

The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded.

Call the backgroundResize() function at the onload event.

    $(document).ready(function(){

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

            $(window).load(function(){
                backgroundResize();
            });

        });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

bootstrap responsive img but change image height and width

From Dev

Responsive container for responsive image

From Dev

Centering image height on responsive site

From Dev

Dynamic Height on Responsive Image Grid?

From Dev

Get image height and change the image container height to auto

From Dev

Responsive triangle with border to container's height and width

From Dev

Bootstrap 3 image responsive height not working

From Dev

Responsive image does not fit the container

From Dev

Vertically align responsive width and height image

From Dev

CSS: Responsive background image height

From Dev

Responsive background image (full height)

From Dev

Constrain table height and image to height of container

From Dev

container/image positioning in responsive design

From Dev

Min-Height interfering with Responsive Image

From Dev

Force responsive image gallery to be the height of it's parent

From Dev

Responsive image scaling with changing max-height

From Dev

Responsive triangle with border to container's height and width

From Dev

Get height of responsive youtube video

From Dev

container should automatically adjust to the height of the background image for responsive design css only

From Dev

Is it possible to make the height of an image responsive (without js)?

From Dev

Vertically align responsive width and height image

From Dev

Set height of container class to height of image

From Dev

Keep ratio height of div with background image in responsive

From Dev

Responsive image height inside Bootstrap column

From Dev

image height inside div container

From Dev

Make Image Height responsive inside responsive container

From Dev

Responsive Css to stick element to container (with height variation of the container)

From Dev

Responsive Video Container -> no width/height issue

From Dev

Responsive background image height

Related Related

  1. 1

    bootstrap responsive img but change image height and width

  2. 2

    Responsive container for responsive image

  3. 3

    Centering image height on responsive site

  4. 4

    Dynamic Height on Responsive Image Grid?

  5. 5

    Get image height and change the image container height to auto

  6. 6

    Responsive triangle with border to container's height and width

  7. 7

    Bootstrap 3 image responsive height not working

  8. 8

    Responsive image does not fit the container

  9. 9

    Vertically align responsive width and height image

  10. 10

    CSS: Responsive background image height

  11. 11

    Responsive background image (full height)

  12. 12

    Constrain table height and image to height of container

  13. 13

    container/image positioning in responsive design

  14. 14

    Min-Height interfering with Responsive Image

  15. 15

    Force responsive image gallery to be the height of it's parent

  16. 16

    Responsive image scaling with changing max-height

  17. 17

    Responsive triangle with border to container's height and width

  18. 18

    Get height of responsive youtube video

  19. 19

    container should automatically adjust to the height of the background image for responsive design css only

  20. 20

    Is it possible to make the height of an image responsive (without js)?

  21. 21

    Vertically align responsive width and height image

  22. 22

    Set height of container class to height of image

  23. 23

    Keep ratio height of div with background image in responsive

  24. 24

    Responsive image height inside Bootstrap column

  25. 25

    image height inside div container

  26. 26

    Make Image Height responsive inside responsive container

  27. 27

    Responsive Css to stick element to container (with height variation of the container)

  28. 28

    Responsive Video Container -> no width/height issue

  29. 29

    Responsive background image height

HotTag

Archive