auto scroll to selected item

This commit is contained in:
MaysWind
2021-02-24 01:51:47 +08:00
parent 2dd2c417d8
commit 5a24ab3f68
7 changed files with 210 additions and 15 deletions
@@ -84,8 +84,9 @@ export default {
}
},
methods: {
onSheetOpen() {
onSheetOpen(event) {
this.currentValue = this.value;
this.scrollToSelectedItem(event.$el);
},
onSheetClosed() {
this.$emit('update:show', false);
@@ -119,6 +120,27 @@ export default {
} else {
return this.currentValue === subItem;
}
},
scrollToSelectedItem(parent) {
if (!parent || !parent.length) {
return;
}
const container = parent.find('.page-content');
const selectedItem = parent.find('.treeview-item .treeview-item-selected');
if (!container.length || !selectedItem.length) {
return;
}
let targetPos = selectedItem.offset().top - container.offset().top - parseInt(container.css('padding-top'), 10)
- (container.outerHeight() - selectedItem.outerHeight()) / 2;
if (targetPos <= 0) {
return;
}
container.scrollTop(targetPos);
}
}
}