Skip to content

Commit

Permalink
Close #1116 gallery: scroll to active item
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Oct 14, 2023
1 parent 3dfccaf commit 71fd9a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/plugin-gallery.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
[GalleryPlugin, {
items: items,
visibleOnLoad: true,
// hideOnClick: false,
// thumbnailSize: {
// width: 100,
// height: 100,
Expand Down
7 changes: 5 additions & 2 deletions packages/gallery-plugin/src/GalleryComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,11 @@ export class GalleryComponent extends AbstractComponent {
currentActive?.classList.remove(ACTIVE_CLASS);

if (id) {
const nextActive = this.items.querySelector(`[data-${GALLERY_ITEM_DATA_KEY}="${id}"]`);
nextActive?.classList.add(ACTIVE_CLASS);
const nextActive = this.items.querySelector(`[data-${GALLERY_ITEM_DATA_KEY}="${id}"]`) as HTMLElement;
if (nextActive) {
nextActive.classList.add(ACTIVE_CLASS);
this.items.scrollLeft = nextActive.offsetLeft + nextActive.clientWidth / 2 - this.items.clientWidth / 2;
}
}
}
}

0 comments on commit 71fd9a0

Please sign in to comment.