Skip to content

Commit

Permalink
feat: use first element as scroll target in continous mode (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
Renji-XD authored Aug 14, 2024
1 parent 88eb94c commit a02b400
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
}
function needScroll(selector: string, scrollMode: string) {
const targetElement = getExternalTargetElement(document, selector);
const targetElement = getExternalTargetElement(document, selector, false);
if (!targetElement || !contentEl) {
return { scroll: false, rect: { top: 0, right: 0, bottom: 0, left: 0 } };
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/lib/functions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,14 @@ export function convertRemToPixels(window: Window, rem: number) {
return rem * parseFloat(window.getComputedStyle(document.documentElement).fontSize);
}

export function getExternalTargetElement(source: Document | Element, selector: string) {
export function getExternalTargetElement(
source: Document | Element,
selector: string,
uselast = true
) {
const elements = [...source.querySelectorAll<HTMLSpanElement>(selector)].filter(
externalTargetFilterFunction
);

return elements[elements.length - 1];
return uselast ? elements[elements.length - 1] : elements[0];
}

0 comments on commit a02b400

Please sign in to comment.