Skip to content

Commit 8ef83d3

Browse files
committed
Fixed scroll issue when scrolling down to elements bigger than window
1 parent f41307e commit 8ef83d3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

intro.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,14 +535,15 @@
535535

536536
if (!_elementInViewport(targetElement.element)) {
537537
var rect = targetElement.element.getBoundingClientRect(),
538-
top = rect.bottom - (rect.bottom - rect.top),
539-
bottom = rect.bottom - _getWinSize().height;
538+
winHeight=_getWinSize().height,
539+
top = rect.bottom - (rect.bottom - rect.top),
540+
bottom = rect.bottom - winHeight;
540541

541542
// Scroll up
542-
if (top < 0) {
543+
if (top < 0 || targetElement.element.clientHeight > winHeight) {
543544
window.scrollBy(0, top - 30); // 30px padding from edge to look nice
544545

545-
// Scroll down
546+
// Scroll down
546547
} else {
547548
window.scrollBy(0, bottom + 100); // 70px + 30px padding from edge to look nice
548549
}

0 commit comments

Comments
 (0)