Skip to content

Commit 36348d0

Browse files
authored
fix(if-needed): scrollTop edge case on subframe (#6)
1 parent 17bde86 commit 36348d0

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"bundlesize": [
7474
{
7575
"path": "./umd/compute-scroll-into-view.min.js",
76-
"maxSize": "3 kB",
76+
"maxSize": "2.5 kB",
7777
"compression": "none"
7878
}
7979
],

src/index.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,10 @@ export default (target: Element, options: Options): CustomScrollAction[] => {
297297
} = frame.getBoundingClientRect()
298298

299299
// If the element is already visible we can end it here
300-
if (scrollMode === 'if-needed') {
300+
if (scrollMode === 'if-needed' && targetTop >= 0 && targetRight >= 0) {
301301
if (
302302
frame === scrollingElement
303-
? targetBottom <= viewportHeight &&
304-
targetTop >= 0 &&
305-
(targetLeft <= viewportWidth && targetRight >= 0)
303+
? targetBottom <= viewportHeight && targetLeft <= viewportWidth
306304
: targetTop >= top && targetBottom <= bottom
307305
) {
308306
// Break the loop and return the computations for things that are not fully visible

0 commit comments

Comments
 (0)