-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adjust scroll logic to do smaller changes (#325)
* adjust scroll logic to do smaller changes * fix lint * only run deploy for master * add missing type definitions
- Loading branch information
Showing
4 changed files
with
61 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
/* eslint no-var: off */ | ||
|
||
const SCROLL_LEEWAY = 30 | ||
module.exports = function updateTocScroll (options) { | ||
var toc = options.tocElement || document.querySelector(options.tocSelector) | ||
if (toc && toc.scrollHeight > toc.clientHeight) { | ||
var activeItem = toc.querySelector('.' + options.activeListItemClass) | ||
if (activeItem) { | ||
toc.scrollTop = activeItem.offsetTop - options.tocScrollOffset | ||
// Determine container top and bottom | ||
var cTop = toc.scrollTop | ||
var cBottom = cTop + toc.clientHeight | ||
|
||
// Determine element top and bottom | ||
var eTop = activeItem.offsetTop | ||
var eBottom = eTop + activeItem.clientHeight | ||
|
||
// Check if out of view | ||
// Above scroll view | ||
if (eTop < cTop + options.tocScrollOffset) { | ||
toc.scrollTop -= (cTop - eTop) + options.tocScrollOffset | ||
// Below scroll view | ||
} else if (eBottom > cBottom - options.tocScrollOffset - SCROLL_LEEWAY) { | ||
toc.scrollTop += (eBottom - cBottom) + options.tocScrollOffset + (2 * SCROLL_LEEWAY) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,6 @@ | |
} | ||
} | ||
|
||
.js-toc { | ||
overflow-y: hidden; | ||
} | ||
|
||
.toc-list { | ||
margin: 0; | ||
padding-left: 10px; | ||
|