mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 00:34:28 +08:00
auto scroll to selected item
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user