Improve scroll for taller elements
Browse files- index.html +13 -0
- src/utils.ts +3 -1
index.html
CHANGED
|
@@ -167,6 +167,7 @@
|
|
| 167 |
<div class="buttons">
|
| 168 |
<button id="highlight-btn">Animated Highlight</button>
|
| 169 |
<button id="buggy-highlight-btn">Buggy Highlight</button>
|
|
|
|
| 170 |
<button id="simple-highlight-btn">Simple Highlight</button>
|
| 171 |
<button id="transition-highlight-btn">Transition Highlight</button>
|
| 172 |
<button id="disallow-close">Disallow Close</button>
|
|
@@ -923,6 +924,18 @@ npm install driver.js</pre
|
|
| 923 |
});
|
| 924 |
});
|
| 925 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 926 |
document.getElementById("highlight-btn").addEventListener("click", () => {
|
| 927 |
driver({
|
| 928 |
animate: true,
|
|
|
|
| 167 |
<div class="buttons">
|
| 168 |
<button id="highlight-btn">Animated Highlight</button>
|
| 169 |
<button id="buggy-highlight-btn">Buggy Highlight</button>
|
| 170 |
+
<button id="off-screen-highlight-btn">Off Screen Highlight</button>
|
| 171 |
<button id="simple-highlight-btn">Simple Highlight</button>
|
| 172 |
<button id="transition-highlight-btn">Transition Highlight</button>
|
| 173 |
<button id="disallow-close">Disallow Close</button>
|
|
|
|
| 924 |
});
|
| 925 |
});
|
| 926 |
|
| 927 |
+
document.getElementById("off-screen-highlight-btn").addEventListener("click", () => {
|
| 928 |
+
driver().highlight({
|
| 929 |
+
element: ".container",
|
| 930 |
+
popover: {
|
| 931 |
+
title: "Buggy Highlight",
|
| 932 |
+
description: "Unlike the older version, new version doesn't work with z-indexes so no more positional issues.",
|
| 933 |
+
side: "bottom",
|
| 934 |
+
align: "start",
|
| 935 |
+
},
|
| 936 |
+
});
|
| 937 |
+
});
|
| 938 |
+
|
| 939 |
document.getElementById("highlight-btn").addEventListener("click", () => {
|
| 940 |
driver({
|
| 941 |
animate: true,
|
src/utils.ts
CHANGED
|
@@ -30,12 +30,14 @@ export function bringInView(element: Element) {
|
|
| 30 |
|
| 31 |
const shouldSmoothScroll = getConfig("smoothScroll");
|
| 32 |
|
|
|
|
|
|
|
| 33 |
element.scrollIntoView({
|
| 34 |
// Removing the smooth scrolling for elements which exist inside the scrollable parent
|
| 35 |
// This was causing the highlight to not properly render
|
| 36 |
behavior: !shouldSmoothScroll || hasScrollableParent(element) ? "auto" : "smooth",
|
| 37 |
inline: "center",
|
| 38 |
-
block: "center",
|
| 39 |
});
|
| 40 |
}
|
| 41 |
|
|
|
|
| 30 |
|
| 31 |
const shouldSmoothScroll = getConfig("smoothScroll");
|
| 32 |
|
| 33 |
+
const isTallerThanViewport = (element as HTMLElement).offsetHeight > window.innerHeight;
|
| 34 |
+
|
| 35 |
element.scrollIntoView({
|
| 36 |
// Removing the smooth scrolling for elements which exist inside the scrollable parent
|
| 37 |
// This was causing the highlight to not properly render
|
| 38 |
behavior: !shouldSmoothScroll || hasScrollableParent(element) ? "auto" : "smooth",
|
| 39 |
inline: "center",
|
| 40 |
+
block: isTallerThanViewport ? "start" : "center",
|
| 41 |
});
|
| 42 |
}
|
| 43 |
|