Skip to content

Commit 1d8d38d

Browse files
committed
Add zoom‑in effect for images
1 parent 2e69b19 commit 1d8d38d

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!-- Checks if page is part of section and page is not section itself -->
2+
{{- if and (ne .Page.Kind "section") (.Page.Section ) }}
3+
<!-- Generate a unique id for each image -->
4+
{{- $random := (substr (md5 .Destination) 0 5) }}
5+
<input type="checkbox" id="zoomCheck-{{$random}}" hidden>
6+
<label for="zoomCheck-{{$random}}">
7+
<img class="zoomCheck" loading="lazy" decoding="async"
8+
src="{{ .Destination | safeURL }}" alt="{{ .Text }}"
9+
{{ with.Title}} title="{{ . }}" {{ end }} />
10+
</label>
11+
{{- else }}
12+
<img loading="lazy" decoding="async" src="{{ .Destination | safeURL }}"
13+
alt="{{ .Text }}" {{ with .Title}} title="{{ . }}" {{ end }} />
14+
{{- end }}

layouts/partials/custom-head.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<style>
2+
@media screen and (min-width: 769px) {
3+
/* .post-content is a class which will be present only on single pages
4+
and not lists and section pages in Hugo */
5+
.page-content input[type="checkbox"]:checked ~ label > img {
6+
transform: scale(1.6);
7+
cursor: zoom-out;
8+
position: relative;
9+
z-index: 999;
10+
}
11+
12+
.page-content img.zoomCheck {
13+
transition: transform 0.15s ease;
14+
z-index: 999;
15+
cursor: zoom-in;
16+
}
17+
}
18+
</style>

0 commit comments

Comments
 (0)