I'm using Nivo Slider to show an image gallery into a responsive website. The slider extends for 100% width and height depends on the aspect ratio of images (all images have the same height).
If user connection is slow (or images are heavy), slider may take a long time before load: during this time, the preloader icon is not shown, since slider has height equal to 0. When slider has loaded, its height jumps to the correct value (depending on images height). This behaviour creates a annoying effect, expecially if we have something (titles, paragraphs..) which has loaded before the slider.
My goal is to impose the correct (final) height to Nivo Slider before images have completely loaded. This would both avoid the annoying "jump effect" and let users to see the preloader icon, preparing them to something which is loading.
Images with known aspect ratio
If I know images aspect ratio before loading, I can edit Nivo Slider CSS to impose the correct final height. My best attempt (with an aspect ratio of 2:1) is the following:
HTML
<div class="theme-default">
<div class="nivoSlider">
<img src="img/one.jpg" />
<img src="img/two.jpg" />
</div>
</div>
CSS
.theme-default {
padding-top: 50%; /* aspect ratio 2:1 */
height:0;
position: relative;
}
.theme-default .nivoSlider {
position:absolute;
left:0;
top:0;
right:0;
bottom:0;
background:#fff url(loading.gif) no-repeat 50% 50%;
}
.theme-default .nivoSlider img {
position:absolute;
top:0px;
left:0px;
display:none;
height: 100% !important;
}
Images with unknown aspect ratio
But if I prior don't know what will be the aspect ratio of images (I only have guarantee that they will have the same height), what can I do? Are there any ways to have a sort of images dimensions "preview" before they are loaded, to let me compute the correct aspect ratio?