I have a container element that has an <img>
tag in it. The width of the image is 100%, and the height is auto
. Overflow on the container is set to hidden
and it also has a max-height
and min-height
. The idea is to have the image determine the height of the container, within the max and min breakpoints.
So, the container has a relative height. In order to have a fluid transition, I reset the height on the resize
event (for a complicated reason, the img
itself does not set the height, rather it is calculated and then changed via javascript). This works fine, and when I resize the window, it all works right.
But some of the logic that is in the resize event I want to run on the load event as well. So, I thought I would just call resize within load, like so:
$(window).load(function(){
$(window).resize();
});
But, this did not work. With this code, if I manually resize the window even just one pixel, the containing element will scale properly (it's about a 200px
difference from the height calculated on load to the reset, properly scaled height).
Apparently, my understanding of how this works is wrong. I have called other events before like this to fire the event and trigger something else. How can I accomplish what I want?