I got two columns of images, done with column-count:2. When I press one of the images, jQuery duplicates that image at the exact same position with position:absolute. Then a class .dupAnim gets added, which makes that image full width and transition it to top:0;left:0 of the page.
So my problem:
When I click an image, the transition from the original state to
top:0; left:0; width:100% isn't working. But when I click the close button, it's perfectly transitioning back.
It seems like the in transition isn't working, but the out transition is working. Below you can find a snippet. Does anyone know what the problem is?
$(".item").each(function(){
var imageSrc = $(this).children('img').attr('src');
$(this).css('background-image', 'url(' + imageSrc + ')');
$(this).find('.clipped').css('background-image', 'url(' + imageSrc + ')');
var imgHeight = $(this).find('img').height();
$(this).css('height', imgHeight + 'px');
});
$(".item").click(function(){
$(this).clone().appendTo(".duplicated").addClass("dupe");
var width = $(this).width();
var height = $(this).height();
var top = $(this).offset().top;
var left = $(this).offset().left;
var dupe = ".dupe";
$(dupe).css({
'width': width + 'px',
'height': height + 'px',
'top': top + 'px',
'left': left + 'px',
'position': 'fixed'
});
$(dupe).addClass("dupAnim");
$(".portfolio-close").fadeIn();
});
$(".portfolio-close").click(function(){
$(".duplicated").find(".dupAnim").removeClass("dupAnim");
setTimeout(function(){
$(".duplicated").children().remove();
}, 500);
$(this).fadeOut();
});
* {
font-family: 'Source Sans Pro', sans-serif;
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.wrapper {
padding: 5% 10%;
}
.wrapper .page-title {
font-size: 4em;
font-weight: 900;
margin-bottom: 20px;
}
.wrapper #portfolio-items {
-webkit-column-count: 2;
-webkit-column-gap: 0px;
-moz-column-count: 2;
-moz-column-gap: 0px;
column-count: 2;
column-gap: 10px;
}
.wrapper #portfolio-items .item {
-webkit-column-break-inside: avoid;
-webkit-backface-visibility: hidden;
border-radius: 8px;
overflow: hidden;
margin: 0 0 10px 0;
cursor: pointer;
width: 100%;
background: #fff;
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
transition: .5s ease-in-out;
}
.wrapper #portfolio-items .item .clipped {
padding: 0 30px 10px 20px;
display: flex;
align-items: flex-end;
height: 100%;
line-height: 1.2;
overflow: hidden;
color: #fff;
font-size: 1.7em;
background: #fff;
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
-webkit-filter: invert(100%) hue-rotate(0deg);
/* change hue-rotate to play with tint */
transition: .5s ease-in-out;
}
.wrapper #portfolio-items .item .clipped .item-title {
overflow: hidden;
}
.wrapper #portfolio-items .item img {
width: 100%;
visibility: hidden;
}
.wrapper #portfolio-items .duplicated .dupe {
position: fixed;
transition: .5s ease-in-out;
}
.wrapper #portfolio-items .duplicated .dupe.dupAnim {
top: 0 !important;
left: 0 !important;
width: 100% !important;
height: 100px !important;
border-radius: 0 !important;
box-shadow: none !important;
transition: .5s ease-in-out;
}
.wrapper #portfolio-items .portfolio-close {
position: fixed;
z-index: 21;
cursor: pointer;
top: 0;
right: 0;
background: #515151;
width: 50px;
height: 50px;
font-size: 30px;
color: white;
padding: 10px 0 0 13px;
line-height: 1;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<div id="portfolio-items">
<div class="item">
<div class="clipped">
<h1 class="item-title">Yoga</h1>
</div>
<img src="https://www.w3schools.com/howto/img_fjords.jpg">
</div>
<div class="item">
<div class="clipped">
<h1 class="item-title">Elephant</h1>
</div>
<img src="https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider2.jpg">
</div>
<div class="item">
<div class="clipped">
<h1 class="item-title">Bird</h1>
</div>
<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg">
</div>
<div class="item">
<div class="clipped">
<h1 class="item-title">View</h1>
</div>
<img src="https://upload.wikimedia.org/wikipedia/commons/6/64/Ailurus_fulgens_RoterPanda_LesserPanda-2.jpg">
</div>
<div class="item">
<div class="clipped">
<h1 class="item-title">Dog</h1>
</div>
<img src="https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/flip.jpg">
</div>
<div class="duplicated"></div>
<div class="portfolio-close">✕</div>
</div>
</div>