Skip to content

Instantly share code, notes, and snippets.

@swasher
Created January 10, 2023 10:36
Show Gist options
  • Save swasher/324263d83b7c5e1cd0aace2065b6d7ac to your computer and use it in GitHub Desktop.
Save swasher/324263d83b7c5e1cd0aace2065b6d7ac to your computer and use it in GitHub Desktop.
How add Zoom feature to Hugo PaperMod
<!-- Just save this file to hugo's -->
<!-- layouts/partials/extend_footer.html -->
<!-- That's all! -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/medium-zoom/1.0.6/medium-zoom.min.js" integrity="sha512-N9IJRoc3LaP3NDoiGkcPa4gG94kapGpaA5Zq9/Dr04uf5TbLFU5q0o8AbRhLKUUlp8QFS2u7S+Yti0U7QtuZvQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
const images = Array.from(document.querySelectorAll(".post-content img"));
images.forEach(img => {
mediumZoom(img, {
margin: 0, /* The space outside the zoomed image */
scrollOffset: 40, /* The number of pixels to scroll to close the zoom */
container: null, /* The viewport to render the zoom in */
template: null, /* The template element to display on zoom */
background: 'rgba(0, 0, 0, 0.8)' /* black back when zoomed */
});
});
</script>
<!-- https://ionic.io/ionicons -->
<script type="module" src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment