update component and add video
This commit is contained in:
1 parent
9f5f3a8e14
commit
bdc54b676b
4 files changed
+959
-44
No files matched your search
@@ -13,10 +13,8 @@ const videoURL = computed(() => frontmatter.value?.video);
|
||||
const videoEl = useTemplateRef("video");
|
||||
|
||||
function setImgClick() {
|
||||
const v = videoEl.value;
|
||||
if (!v) {
|
||||
return;
|
||||
}
|
||||
document.removeEventListener("click", imgClickListener);
|
||||
document.addEventListener("click", imgClickListener);
|
||||
|
||||
document.querySelectorAll("img").forEach((img) => {
|
||||
const [, min, sec] = /^(\d+)\:(\d+)$/.exec(img.alt) || [];
|
||||
@@ -24,13 +22,23 @@ function setImgClick() {
|
||||
if (!t) return;
|
||||
|
||||
img.title = img.title || img.alt;
|
||||
|
||||
img.onclick = () => {
|
||||
v.currentTime = t;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function imgClickListener(ev: PointerEvent) {
|
||||
if (!(ev.target instanceof HTMLImageElement)) return;
|
||||
const img = ev.target;
|
||||
|
||||
if (!videoEl.value) return;
|
||||
const v = videoEl.value;
|
||||
|
||||
const [, min, sec] = /^(\d+)\:(\d+)$/.exec(img.alt) || [];
|
||||
const t = min && sec ? parseInt(min) * 60 + parseInt(sec) : null;
|
||||
if (!t) return;
|
||||
|
||||
v.currentTime = t;
|
||||
}
|
||||
|
||||
watch(videoURL, () => {
|
||||
setImgClick();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user