simple galery

by oceog

HTML

<button id="prev">Prev</button>
<button id="next">Next</button>
<div id='show'>
    <div class="images">
        <img src="http://placehold.it/350x150" />
    </div>
    <div class="images" style="display:none;">
        <img/>
    </div>
</div>

CSS

#big.images {
    display: none;
}
.images {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;
    top: 0;
    left: 0;
}
#show {
    position: absolute;
    width: 350px;
    height: 150px;
    border: 1px solid;
    left: 20px;
    top: 50px;
}

JavaScript

var image_list = [
    '350x150', '400x250', '200x250', '300x250', '600x800', '800x600'];
var image_base = "http://placehold.it/";

$('button').click(function () {
    var $this = $(this);
    var button = $this.attr('id');
    if (button == 'prev') {
        image_list.unshift(image_list.pop());
    }
    if (button == 'next') {
        image_list.push(image_list.shift());
    }
    var src = image_base + image_list[0];
    var image = $('#show .images').last().find('img');
    image.one('load', show_parent_hide_siblings);
    image.attr('src', src);
    if (image.get(0).complete) {
        console.log(image.get(0).complete);
        image.trigger('load');
    }
});

function show_parent_hide_siblings(image) {
    var $this = $(this);
    var parent = $this.parent();
    var w = $this.get(0).width,
        h = $this.get(0).height;
    parent.parent().append($this.parent().siblings());
    parent.parent().finish().animate({
        width: w,
        height: h
    }, 1000);
    parent.fadeIn(1000);
    parent.siblings().fadeOut(1000);
}