fix script not working
All checks were successful
Build and Deploy Astro App / build_and_deploy (push) Successful in 50s
All checks were successful
Build and Deploy Astro App / build_and_deploy (push) Successful in 50s
This commit is contained in:
parent
9de57af445
commit
d84c5a9973
2 changed files with 24 additions and 25 deletions
23
blog/public/scripts/image-modal.js
Normal file
23
blog/public/scripts/image-modal.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
const backdrop = document.querySelector("#image-backdrop");
|
||||
const preview = document.querySelector("#image-preview");
|
||||
|
||||
if (backdrop instanceof HTMLElement && preview instanceof HTMLImageElement) {
|
||||
document.addEventListener("click", (event) => {
|
||||
if (!(event.target instanceof Element)) return;
|
||||
|
||||
if (!backdrop.hidden && backdrop.contains(event.target)) {
|
||||
backdrop.hidden = true;
|
||||
document.body.style.overflow = "";
|
||||
return;
|
||||
}
|
||||
|
||||
const image = event.target.closest("article img");
|
||||
|
||||
if (!(image instanceof HTMLImageElement)) return;
|
||||
|
||||
preview.src = image.currentSrc || image.src;
|
||||
preview.alt = image.alt;
|
||||
backdrop.hidden = false;
|
||||
document.body.style.overflow = "hidden";
|
||||
});
|
||||
}
|
||||
|
|
@ -43,31 +43,7 @@ const localeDate = formatLocalizedDateString(frontmatter.date);
|
|||
</div>
|
||||
</Main>
|
||||
|
||||
<script>
|
||||
const backdrop = document.querySelector("#image-backdrop");
|
||||
const preview = document.querySelector("#image-preview");
|
||||
|
||||
if (backdrop instanceof HTMLElement && preview instanceof HTMLImageElement) {
|
||||
document.addEventListener("click", (event) => {
|
||||
if (!(event.target instanceof Element)) return;
|
||||
|
||||
if (!backdrop.hidden && backdrop.contains(event.target)) {
|
||||
backdrop.hidden = true;
|
||||
document.body.style.overflow = "";
|
||||
return;
|
||||
}
|
||||
|
||||
const image = event.target.closest("article img");
|
||||
|
||||
if (!(image instanceof HTMLImageElement)) return;
|
||||
|
||||
preview.src = image.currentSrc || image.src;
|
||||
preview.alt = image.alt;
|
||||
backdrop.hidden = false;
|
||||
document.body.style.overflow = "hidden";
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<script is:inline src="/scripts/image-modal.js"></script>
|
||||
|
||||
<style>
|
||||
article {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue