mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-29 03:53:30 +08:00
refactor(gallery): add openGallery method
This commit is contained in:
parent
2e1633b807
commit
7ca67456b4
@ -115,16 +115,7 @@ class StackGallery {
|
|||||||
return Promise.all(tasks);
|
return Promise.all(tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
private initPS() {
|
private openGallery(index: number) {
|
||||||
const pswp = document.querySelector('.pswp') as HTMLDivElement;
|
|
||||||
pswp.style.removeProperty('display');
|
|
||||||
|
|
||||||
for (const [index, item] of this.items.entries()) {
|
|
||||||
const a = item.el.querySelector('a');
|
|
||||||
|
|
||||||
a.addEventListener('click', (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
const pswp = document.querySelector('.pswp') as HTMLDivElement;
|
const pswp = document.querySelector('.pswp') as HTMLDivElement;
|
||||||
const ps = new window.PhotoSwipe(pswp, window.PhotoSwipeUI_Default, this.items, {
|
const ps = new window.PhotoSwipe(pswp, window.PhotoSwipeUI_Default, this.items, {
|
||||||
index: index,
|
index: index,
|
||||||
@ -138,6 +129,18 @@ class StackGallery {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ps.init();
|
ps.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private initPS() {
|
||||||
|
const pswp = document.querySelector('.pswp') as HTMLDivElement;
|
||||||
|
pswp.style.removeProperty('display');
|
||||||
|
|
||||||
|
for (const [index, item] of this.items.entries()) {
|
||||||
|
const a = item.el.querySelector('a');
|
||||||
|
|
||||||
|
a.addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
this.openGallery(index);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user