add pdf viewer - page change observer working
This commit is contained in:
parent
ef2eeafa8d
commit
ade5ac6a4e
5 changed files with 882 additions and 45 deletions
|
|
@ -53,6 +53,7 @@
|
|||
</p>
|
||||
</div>
|
||||
<div
|
||||
@click="emit('update:step', 'PdfViewer')"
|
||||
class="card card--cta | flex-1 | h-full"
|
||||
style="--padding: var(--space-32); --row-gap: var(--space-32)"
|
||||
>
|
||||
|
|
|
|||
55
src/components/project/client-brief/PdfViewer.vue
Normal file
55
src/components/project/client-brief/PdfViewer.vue
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<template>
|
||||
<div>
|
||||
<div :style="{ width: '1028px', height: '700px', margin: '0 auto' }">
|
||||
<VPdfViewer
|
||||
src="https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf"
|
||||
local="fr_FR"
|
||||
@loaded="onPdfLoaded"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { VPdfViewer } from "@vue-pdf-viewer/viewer";
|
||||
|
||||
const onPdfLoaded = () => {
|
||||
console.log("PDF chargé, mise en place de l'observation.");
|
||||
|
||||
const wrapper = document.querySelector(".vpv-pages-inner-container");
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
entries.forEach((entry, index) => {
|
||||
if (entry.intersectionRatio > 0.5) {
|
||||
console.log(entry.target.getAttribute("aria-label"));
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
root: wrapper,
|
||||
threshold: [0.5],
|
||||
}
|
||||
);
|
||||
|
||||
const observePages = () => {
|
||||
const pages = document.querySelectorAll(".vpv-page-inner-container");
|
||||
pages.forEach((page) => {
|
||||
if (!page.__observed__) {
|
||||
observer.observe(page);
|
||||
page.__observed__ = true;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const mutationObserver = new MutationObserver(() => {
|
||||
observePages();
|
||||
});
|
||||
|
||||
if (wrapper) {
|
||||
mutationObserver.observe(wrapper, { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
observePages();
|
||||
};
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue