Skip to content

Commit ece5b11

Browse files
committed
Implement the non-javascript image zoom-in effect.
Add a zoom-in effect for better visibility by following this post: https://adityatelange.in/blog/hugo-image-zoom-in/ But I am leveraging ox-hugo to export org-mode to Hugo markdown, ox-hugo uses `figure` shortcodes rather than standard Markdown image, so I need to tweak the figure shortcode to apply the approach.
1 parent 6327fee commit ece5b11

File tree

3 files changed

+92
-13
lines changed

3 files changed

+92
-13
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
@media screen and (min-width: 769px) {
2+
/* Position relative on the container to create a stacking context */
3+
.post-content {
4+
position: relative;
5+
}
6+
7+
/* Hide the checkbox visually */
8+
.post-content input[type="checkbox"] {
9+
position: absolute;
10+
opacity: 0;
11+
}
12+
13+
/* When checkbox is checked, create a fullscreen overlay */
14+
.post-content input[type="checkbox"]:checked ~ label::before {
15+
content: "";
16+
position: fixed;
17+
top: 0;
18+
left: 0;
19+
right: 0;
20+
bottom: 0;
21+
background-color: rgba(255, 255, 255, 0.8);
22+
backdrop-filter: blur(5px);
23+
-webkit-backdrop-filter: blur(5px);
24+
z-index: 998;
25+
}
26+
27+
/* Style for the zoomed image */
28+
.post-content input[type="checkbox"]:checked ~ label > img {
29+
position: fixed;
30+
top: 50%;
31+
left: 50%;
32+
transform: translate(-50%, -50%) scale(1);
33+
max-height: 90vh; /* Maximum height: 90% of viewport height */
34+
max-width: 90vw; /* Maximum width: 90% of viewport width */
35+
width: auto;
36+
height: auto;
37+
object-fit: contain;
38+
cursor: zoom-out;
39+
z-index: 999;
40+
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
41+
}
42+
43+
/* Normal image style */
44+
.post-content img.zoomCheck {
45+
transition: all 0.3s ease;
46+
cursor: zoom-in;
47+
max-width: 100%;
48+
height: auto;
49+
}
50+
}

layouts/partials/extend_footer.html

Lines changed: 0 additions & 13 deletions
This file was deleted.

layouts/shortcodes/figure.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{{- $random := (substr (md5 (.Get "src")) 0 5) }}
2+
<figure{{ if or (.Get "class") (eq (.Get "align") "center") }} class="
3+
{{- if eq (.Get "align") "center" }}align-center {{ end }}
4+
{{- with .Get "class" }}{{ . }}{{- end }}"
5+
{{- end -}}>
6+
{{- if .Get "link" -}}
7+
<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
8+
{{- end }}
9+
10+
<!-- Zoom functionality start -->
11+
<input type="checkbox" id="zoomCheck-{{$random}}" hidden>
12+
<label for="zoomCheck-{{$random}}">
13+
<!-- Zoom functionality end -->
14+
15+
<img class="zoomCheck" loading="lazy" src="{{ .Get "src" }}{{- if eq (.Get "align") "center" }}#center{{- end }}"
16+
{{- if or (.Get "alt") (.Get "caption") }}
17+
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}"
18+
{{- end -}}
19+
{{- with .Get "width" }} width="{{ . }}"{{ end -}}
20+
{{- with .Get "height" }} height="{{ . }}"{{ end -}}
21+
/> <!-- Closing img tag -->
22+
23+
<!-- Closing label for zoom -->
24+
</label>
25+
26+
{{- if .Get "link" }}</a>{{ end -}}
27+
{{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
28+
<figcaption>
29+
{{ with (.Get "title") -}}
30+
{{ . }}
31+
{{- end -}}
32+
{{- if or (.Get "caption") (.Get "attr") -}}<p>
33+
{{- .Get "caption" | markdownify -}}
34+
{{- with .Get "attrlink" }}
35+
<a href="{{ . }}">
36+
{{- end -}}
37+
{{- .Get "attr" | markdownify -}}
38+
{{- if .Get "attrlink" }}</a>{{ end }}</p>
39+
{{- end }}
40+
</figcaption>
41+
{{- end }}
42+
</figure>

0 commit comments

Comments
 (0)