<div class="container">
<img src="https://i.ytimg.com/vi/NHfttfWo-RA/hqdefault.jpg" />
<img src="https://img.buzzfeed.com/buzzfeed-static/static/2014-07/11/23/enhanced/webdr05/enhanced-32427-1405134811-5.jpg " />
</div>
.container {
position: relative;
}
.container img {
width: 100vw;
object-fit: contain;
height: 100vh;
position: absolute;
top: 0px;
left: 0px;
transition: 2s opacity;
}
.container img:nth-child(1) {
opacity: 1;
}
.container img:nth-child(2) {
opacity: 0;
}
.container.cross img:nth-child(1) {
opacity: 0;
}
.container.cross img:nth-child(2) {
opacity: 1;
}
var c = document.querySelector('.container');
c.addEventListener('click', function() {
c.classList.toggle('cross');
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.