1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.scrollItemIntoView = scrollItemIntoView;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | function scrollItemIntoView(child, parent, isFirst, isLast) {
|
25 | var scrollAlignInView = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'auto';
|
26 | if (!child) return;
|
27 | var childRect = child.getBoundingClientRect();
|
28 | var parentRect = parent.getBoundingClientRect();
|
29 |
|
30 | if (childRect.bottom > parentRect.bottom) {
|
31 | if (isLast) {
|
32 | parent.scrollTop = parent.scrollHeight - parentRect.height;
|
33 | } else {
|
34 | var targetBottom = child.offsetTop + childRect.height;
|
35 | parent.scrollTop = targetBottom - (scrollAlignInView === 'center' ? Math.round((parentRect.height + childRect.height) / 2) : parentRect.height);
|
36 | }
|
37 |
|
38 | } else if (childRect.top < parentRect.top) {
|
39 | if (isFirst) {
|
40 | parent.scrollTop = 0;
|
41 | } else {
|
42 | parent.scrollTop = child.offsetTop - (scrollAlignInView === 'center' ? Math.round((parentRect.height - childRect.height) / 2) : 0);
|
43 | }
|
44 | }
|
45 | } |
\ | No newline at end of file |