css:
img.modal-img {
cursor: pointer;
transition: 0.3s;
}
img.modal-img:hover {
opacity: 0.7;
}
.img-modal {
display: none;
position: fixed;
z-index: 99999;
padding-top: 100px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.9);
}
.img-modal img {
margin: auto;
display: block;
width: 80%;
max-width: 700%;
}
.img-modal div {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
text-align: center;
color: #ccc;
padding: 10px 0;
height: 150px;
}
.img-modal img, .img-modal div {
animation: zoom 0.6s;
}
.img-modal span {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
cursor: pointer;
}
@media only screen and (max-width: 700px) {
.img-modal img {
width: 100%;
}
}
@keyframes zoom {
0% {
transform: scale(0);
}
100% {
transform: scale(1);
}
}
Javascript:
$('img.modal-img').each(function() {_x000D_
var modal = $('<div class="img-modal"><span>×</span><img /><div></div></div>');_x000D_
modal.find('img').attr('src', $(this).attr('src'));_x000D_
if($(this).attr('alt'))_x000D_
modal.find('div').text($(this).attr('alt'));_x000D_
$(this).after(modal);_x000D_
modal = $(this).next();_x000D_
$(this).click(function(event) {_x000D_
modal.show(300);_x000D_
modal.find('span').show(0.3);_x000D_
});_x000D_
modal.find('span').click(function(event) {_x000D_
modal.hide(300);_x000D_
});_x000D_
});_x000D_
$(document).keyup(function(event) {_x000D_
if(event.which==27)_x000D_
$('.img-modal>span').click();_x000D_
});
_x000D_
img.modal-img {_x000D_
cursor: pointer;_x000D_
transition: 0.3s;_x000D_
}_x000D_
img.modal-img:hover {_x000D_
opacity: 0.7;_x000D_
}_x000D_
.img-modal {_x000D_
display: none;_x000D_
position: fixed;_x000D_
z-index: 99999;_x000D_
padding-top: 100px;_x000D_
left: 0;_x000D_
top: 0;_x000D_
width: 100%;_x000D_
height: 100%;_x000D_
overflow: auto;_x000D_
background-color: rgba(0,0,0,0.9);_x000D_
}_x000D_
.img-modal img {_x000D_
margin: auto;_x000D_
display: block;_x000D_
width: 80%;_x000D_
max-width: 700%;_x000D_
}_x000D_
.img-modal div {_x000D_
margin: auto;_x000D_
display: block;_x000D_
width: 80%;_x000D_
max-width: 700px;_x000D_
text-align: center;_x000D_
color: #ccc;_x000D_
padding: 10px 0;_x000D_
height: 150px;_x000D_
}_x000D_
.img-modal img, .img-modal div {_x000D_
animation: zoom 0.6s;_x000D_
}_x000D_
.img-modal span {_x000D_
position: absolute;_x000D_
top: 15px;_x000D_
right: 35px;_x000D_
color: #f1f1f1;_x000D_
font-size: 40px;_x000D_
font-weight: bold;_x000D_
transition: 0.3s;_x000D_
cursor: pointer;_x000D_
}_x000D_
@media only screen and (max-width: 700px) {_x000D_
.img-modal img {_x000D_
width: 100%;_x000D_
}_x000D_
}_x000D_
@keyframes zoom {_x000D_
0% {_x000D_
transform: scale(0);_x000D_
}_x000D_
100% {_x000D_
transform: scale(1);_x000D_
}_x000D_
}_x000D_
Javascript:_x000D_
_x000D_
$('img.modal-img').each(function() {_x000D_
var modal = $('<div class="img-modal"><span>×</span><img /><div></div></div>');_x000D_
modal.find('img').attr('src', $(this).attr('src'));_x000D_
if($(this).attr('alt'))_x000D_
modal.find('div').text($(this).attr('alt'));_x000D_
$(this).after(modal);_x000D_
modal = $(this).next();_x000D_
$(this).click(function(event) {_x000D_
modal.show(300);_x000D_
modal.find('span').show(0.3);_x000D_
});_x000D_
modal.find('span').click(function(event) {_x000D_
modal.hide(300);_x000D_
});_x000D_
});_x000D_
$(document).keyup(function(event) {_x000D_
if(event.which==27)_x000D_
$('.img-modal>span').click();_x000D_
});_x000D_
_x000D_
HTML:
_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>_x000D_
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>_x000D_
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>_x000D_
<img src="http://www.google.com/favicon.ico" class="modal-img">
_x000D_