I have written a little script to create a clone of clicked image and expand it to the size of the parent ul. I would like to make the clone fade in somehow and fade out giving it a nice effect.
Note: If you see any code improvements please point them out so fix that.
Here is my jsfiddle: http://jsfiddle.net/jnLLLtt4/1/
Jquery:
$(document).ready(function () {
$('.thumb-item').on('click', function() {
var currentId = $(this).attr('id'),
extraimg = $('#' + currentId).clone(),
currentOffset = $('#' + currentId).offset(),
parent = $('.image-gallery'),
parentOffset = parent.offset();
extraimg
.css({
'position': 'absolute',
'background-position': 'top',
'top': currentOffset.top + 'px',
'left': currentOffset.left + 'px',
'margin': '0'
})
.appendTo(parent)
//make bigger
extraimg.css({
'height': parent.height() + 'px',
'width': parent.width() + 'px',
'top': parentOffset.top + 'px',
'left': parentOffset.left + 'px'
})
.on('click', function () {
$(this).stop(true).remove();
});
});
});
html:
<ul class="image-gallery">
<li class="thumb-item" id="image_1" style="background-image:url('http://placehold.it/200x200');"></li>
<li class="thumb-item" id="image_2" style="background-image:url('http://placehold.it/200x200');"></li>
<li class="thumb-item" id="image_3" style="background-image:url('http://placehold.it/200x200');"></li>
<li class="thumb-item" id="image_4" style="background-image:url('http://placehold.it/200x200');"></li>
</ul>