/* POP BOX */
;(function() {
var $pop = $("#pop");
$(document).on("click", "[data-pop]", function() {
var popSrc= $(this).data("pop"),
docW= Math.max(document.documentElement.clientWidth, window.innerWidth || 0),
docH= Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
$pop.addClass("visible loading").css({backgroundImage:"none"});
$("<img/>").on("load", function() {
var bigger = (this.width > docW || this.height > docH)
$pop.removeClass("loading").css({
backgroundSize: bigger ? "contain" : "auto",
backgroundImage: "url(" + this.src + ")"
});
}).attr("src", popSrc);
});
$("#popClose").on("click", function() {
$pop.removeClass("visible loading");
});
}());
/*
POP BOX
*/
#pop {
position: fixed;
z-index: 999999;
color: #fff;
background: rgba(0, 0, 0, 0.6) none no-repeat 50% 50%;
box-shadow: 0 0 0 24px rgba(0, 0, 0, 0.6);
left: 24px;
top: 24px;
right: 24px;
bottom: 24px;
transition: 0.3s;
visibility: hidden;
opacity: 0;
}
#pop.loading:after {
content: "Loading...";
position: absolute;
top: 50%;
left: 44%;
}
#pop.visible {
visibility: visible;
opacity: 1;
}
#popClose {
cursor: pointer;
position: absolute;
top: 0px;
right: 0px;
font-size: 2em;
}
<!-- POP BOX -->
<div id="pop"><a id="popClose">×</a></div>
<!-- USE EXAMPLE -->
<img src="http://placehold.it/50x50/0bf" data-pop="http://placehold.it/860x590/0bf" alt="" />
<img src="http://placehold.it/50x50/f0b" data-pop="http://placehold.it/590x860/f0b" alt="" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>