I have created a nice little image gallery for the web. I set out wanting 3 things. 1. The whole gallery had a basic level responsiveness to it. 2. The gallery would take images of any size, and display them without cropping. 3. The gallery would run automatically. If you look here(JSFiddle) I have done just that. The automatic slide show is just a small bit of jQuery.
setInterval(function () {
$(".image_background").last().animate({
left: '-=1000'
}, 1000, 'swing', function() {
var top_element= $(this).detach();
top_element.css({"left": 0});
$(".image_gallery").prepend(top_element);
})}, 2000);
I am quite happy with it. It's the css bit that I am not so sure about.
.main_image_gallery{
display: inline-block;
position: absolute;
height: 50%;
width: 30%;
z-index: 2;
top: 30%;
left: 3%;
background-color: #4e9ba1;
box-sizing: border-box;
overflow: hidden;
}
.image_background{
background-color: #4e9ba1;
display: inline-block;
position: absolute;
height: 100%;
width: 100%;
}
.gallery_image{
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
max-width: 100%;
max-height: 100%;
}
For reference, here's the HTML
<div class="main_image_gallery image_gallery">
<div class="image_background">
<img class="gallery_image" src="http://www.vectortemplates.com/raster/batman-logo-big.gif" ></img>
</div>
<div class="image_background">
<img class="gallery_image" src="http://www.vectortemplates.com/raster/batman-logo.gif" ></img>
</div>
<div class="image_background">
<img class="gallery_image" src="http://th09.deviantart.net/fs70/PRE/f/2011/290/8/e/batman_logo_circleless_by_machsabre-d4d6s56.png" ></img>
</div>
</div>
I feel like there is a simpler way to do it. Any thoughts on how I can clean it up, maybe improve the responsive aspects?