JSFiddle - React, Tailwind, and code Playground
by ginpei
HTML
<div id="overlay">
<div class="dialog">
<div class="header">
<div class="title">Kitty sais mew</div>
<div class="close">close</div>
</div>
<div class="img">
<img />
</div>
<p class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
<p>Click image to see in large size.</p>
<div id="dummy"></div>
<p>These cats from <a href="http://placekitten.com/">{placekitten}</a>.</p>
CSS
body {
font-family: serif;
font-size: 14px;
}
p {
margin: 1em;
}
#dummy {
text-align: center;
}
#dummy a img {
border: 1px solid #eee;
}
#dummy a:hover img {
border-color: #999;
}
#overlay {
background-color: rgba(0,0,0,.5);
display: none;
height: 100%;
left: 0;
overflow: auto;
position: fixed;
top: 0;
width: 100%;
}
.dialog {
background-color: #fff;
border: solid 1px #999;
border-radius: 10px;
box-shadow:
1px 1px 0 #fff,
-1px -1px 0 #fff,
1px -1px 0 #fff,
-1px 1px 0 #fff;
margin: 40px auto 10px;
width: 80%;
}
.header {
padding: .1em .5em;
}
.title {
float: left;
font-weight: bold;
text-transform: uppercase;
}
.close {
color: #00f;
cursor: pointer;
float: right;
text-decoration: underline;
}
.img {
text-align: center;
margin: 2em;
}
.text {
line-height: 1.5em;
}
.text:first-letter {
float: left;
font-size: 3em;
line-height: 1em;
margin-right: .1em;
}
JavaScript
(function($) {
// show image
$(document).on('click', 'a', function(event) {
event.preventDefault();
var $link = $(this);
var $img = $link.find('img');
// update image
$('#overlay img').attr({
height: $img.attr('data-height'),
src: $img.attr('src'),
width: $img.attr('data-width')
});
// centering
var $dialog = $('#overlay .dialog');
var height = $dialog.outerHeight(true);
// show dialog
$('#overlay').fadeIn();
});
// close dialog
$('#overlay').click(function(event) {
var $target = $(event.target);
if ($target.is('#overlay') || $target.closest('.close').length > 0) {
$(this).hide();
}
});
}(jQuery));
// build dummy contents
(function($) {
function size(base, tolerance) {
return base + (Math.random() * tolerance * 2 | 0) - tolerance;
}
var i, MAX = 30, html = '';
for (i = 0; i < MAX; i++) {
var w = size(300, 50);
var h = size(200, 50);
var u = 'http://placekitten.com/' + w + '/' + h;
html +=
'<p>' +
'<a href="' + u + '">' +
'<img src="' + u + '" ' +
'width="' + parseInt(w/2, 10) + '" ' +
'height="' + parseInt(h/2, 10) + '" ' +
'data-width="' + w + '" ' +
'data-height="' + h + '">' +
'</a>' +
'</p>';
}
$('#dummy').html(html);
}(jQuery));