You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
1 month ago
|
'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports.default = scrollIntoView;
|
||
|
|
||
|
var _vue = require('vue');
|
||
|
|
||
|
var _vue2 = _interopRequireDefault(_vue);
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
|
||
|
function scrollIntoView(container, selected) {
|
||
|
if (_vue2.default.prototype.$isServer) return;
|
||
|
|
||
|
if (!selected) {
|
||
|
container.scrollTop = 0;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var offsetParents = [];
|
||
|
var pointer = selected.offsetParent;
|
||
|
while (pointer && container !== pointer && container.contains(pointer)) {
|
||
|
offsetParents.push(pointer);
|
||
|
pointer = pointer.offsetParent;
|
||
|
}
|
||
|
var top = selected.offsetTop + offsetParents.reduce(function (prev, curr) {
|
||
|
return prev + curr.offsetTop;
|
||
|
}, 0);
|
||
|
var bottom = top + selected.offsetHeight;
|
||
|
var viewRectTop = container.scrollTop;
|
||
|
var viewRectBottom = viewRectTop + container.clientHeight;
|
||
|
|
||
|
if (top < viewRectTop) {
|
||
|
container.scrollTop = top;
|
||
|
} else if (bottom > viewRectBottom) {
|
||
|
container.scrollTop = bottom - container.clientHeight;
|
||
|
}
|
||
|
}
|