Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit d67e6c0

Browse files
fix: sections scroll issue (#327)
Fixes the issue outlined in #28 Also to make it more friendly I added some scrolling logic to keep the active element on the table in view. I tried to apply the smooth scrolling though that seems to cause it to fail. While this could be achieved via Jquery I believe it would be more visually distracting to suddenly see another list scrolling smoothly rather than jumping to the right location, though it should be relatively easy to add should it be requested.
2 parents 3527dfb + 1430757 commit d67e6c0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

theme/_layouts/examples.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,25 @@
6363
{% endif %}
6464
{% include site-footer.html %}
6565
</div><!-- /.js-footer-area -->
66+
<!-- Custom ScrollSpy Logic -->
67+
<script>
68+
$(document).ready(function() {
69+
$('[data-spy="scroll"]').on('activate.bs.scrollspy', function (event) {
70+
const highlightedElement = $(event.target);
71+
72+
if (highlightedElement.length) {
73+
const elementRect = highlightedElement[0].getBoundingClientRect();
74+
const container = highlightedElement.parent().parent()[0];
75+
const containerRect = container.getBoundingClientRect();
76+
77+
const isOutOfView = elementRect.top < containerRect.top || elementRect.bottom > containerRect.bottom;
78+
79+
if (isOutOfView) {
80+
highlightedElement[0].scrollIntoView();
81+
}
82+
}
83+
});
84+
});
85+
</script>
6686
</body>
6787
</html>

theme/_sass/components/_sections-list.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
.sections-list.affix {
1818
position: fixed;
1919
top: 90px;
20+
bottom: 20px;
21+
overflow: scroll;
2022
}
2123

2224
.sections-list.affix-bottom {

0 commit comments

Comments
 (0)