mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
Fix dropdown opening direction [SCI-9428]
This commit is contained in:
parent
64449af994
commit
1acf67db5a
2 changed files with 22 additions and 14 deletions
14
app/javascript/vue/shared/isInViewPort.js
Normal file
14
app/javascript/vue/shared/isInViewPort.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
export function isInViewPort(el) {
|
||||||
|
const rect = el.getBoundingClientRect();
|
||||||
|
|
||||||
|
return (
|
||||||
|
rect.top >= 0 &&
|
||||||
|
rect.left >= 0 &&
|
||||||
|
rect.bottom <=
|
||||||
|
(window.innerHeight ||
|
||||||
|
document.documentElement.clientHeight) /*or $(window).height() */ &&
|
||||||
|
rect.right <=
|
||||||
|
(window.innerWidth ||
|
||||||
|
document.documentElement.clientWidth) /*or $(window).width() */
|
||||||
|
);
|
||||||
|
}
|
|
@ -63,6 +63,8 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
import { isInViewPort } from './isInViewPort.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'DropdownMenu',
|
name: 'DropdownMenu',
|
||||||
props: {
|
props: {
|
||||||
|
@ -82,18 +84,19 @@ export default {
|
||||||
watch: {
|
watch: {
|
||||||
showMenu() {
|
showMenu() {
|
||||||
if (this.showMenu) {
|
if (this.showMenu) {
|
||||||
|
this.openUp = false;
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.$refs.flyout.style.marginBottom = `${this.$refs.openBtn.offsetHeight}px`;
|
this.$refs.flyout.style.marginBottom = `${this.$refs.openBtn.offsetHeight}px`;
|
||||||
this.verticalPositionFlyout();
|
this.updateOpenDirectoin();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
document.addEventListener('scroll', this.verticalPositionFlyout);
|
document.addEventListener('scroll', this.updateOpenDirectoin);
|
||||||
},
|
},
|
||||||
unmounted() {
|
unmounted() {
|
||||||
document.removeEventListener('scroll', this.verticalPositionFlyout);
|
document.removeEventListener('scroll', this.updateOpenDirectoin);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
closeMenu() {
|
closeMenu() {
|
||||||
|
@ -110,20 +113,11 @@ export default {
|
||||||
|
|
||||||
this.closeMenu();
|
this.closeMenu();
|
||||||
},
|
},
|
||||||
verticalPositionFlyout() {
|
updateOpenDirectoin() {
|
||||||
if (!this.showMenu) return;
|
if (!this.showMenu) return;
|
||||||
|
|
||||||
const btn = this.$refs.openBtn;
|
this.openUp = !isInViewPort(this.$refs.flyout);
|
||||||
const screenHeight = window.innerHeight;
|
|
||||||
const btnBottom = btn.getBoundingClientRect().bottom;
|
|
||||||
|
|
||||||
if (screenHeight / 2 < btnBottom) {
|
|
||||||
this.openUp = true;
|
|
||||||
} else {
|
|
||||||
this.openUp = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue