Skip to content

Commit

Permalink
Add image popup
Browse files Browse the repository at this point in the history
  • Loading branch information
hankhjliao committed Feb 16, 2024
1 parent 0c7ff80 commit 45491de
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions assets/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,32 @@ var Footnotes = {
$('#footnote-div').stop();
}
}

$('.post-content img').click(function () {
var src = $(this).attr('src');
var modal;

function removeModal() {
modal.remove();
$(document.body).off('keyup.modal-close');
}

modal = $('<div>').css({
background: 'rgba(0,0,0,.75) no-repeat center / 80% url(' + src + ')',
position: 'fixed',
zIndex: '9999',
top: '0',
left: '0',
right: '0',
bottom: '0',
cursor: 'zoom-out'
}).click(function () {
removeModal();
}).appendTo(document.body);

$(document.body).on('keyup.modal-close', function (e) {
if (e.key === 'Escape') {
removeModal();
}
});
});

0 comments on commit 45491de

Please sign in to comment.